Project

General

Profile

0001-Fixes-263-correct-pluralization-of-medium-media.patch

Proposed patch - Jochen Schalanda, 05/23/2010 09:22 AM

View differences:

app/controllers/media_controller.rb
1
class MediaController < ApplicationController
2
  def index
3
    @media = Medium.all(:include => [:operatingsystem])
4
  end
5

  
6
  def new
7
    @medium = Medium.new
8
  end
9

  
10
  def create
11
    @medium = Medium.new(params[:medium])
12
    if @medium.save
13
      flash[:notice] = "Successfully created medium."
14
      redirect_to media_url
15
    else
16
      render :action => 'new'
17
    end
18
  end
19

  
20
  def edit
21
    @medium = Medium.find(params[:id])
22
  end
23

  
24
  def update
25
    @medium = Medium.find(params[:id])
26
    if @medium.update_attributes(params[:medium])
27
      flash[:notice] = "Successfully updated medium."
28
      redirect_to media_url
29
    else
30
      render :action => 'edit'
31
    end
32
  end
33

  
34
  def destroy
35
    @medium = Medium.find(params[:id])
36
    @medium.destroy
37
    flash[:notice] = "Successfully destroyed medium."
38
    redirect_to media_url
39
  end
40
end
app/controllers/medias_controller.rb
1
class MediasController < ApplicationController
2
  def index
3
    @medias = Media.all(:include => [:operatingsystem])
4
  end
5

  
6
  def new
7
    @media = Media.new
8
  end
9

  
10
  def create
11
    @media = Media.new(params[:media])
12
    if @media.save
13
      flash[:notice] = "Successfully created media."
14
      redirect_to medias_url
15
    else
16
      render :action => 'new'
17
    end
18
  end
19

  
20
  def edit
21
    @media = Media.find(params[:id])
22
  end
23

  
24
  def update
25
    @media = Media.find(params[:id])
26
    if @media.update_attributes(params[:media])
27
      flash[:notice] = "Successfully updated media."
28
      redirect_to medias_url
29
    else
30
      render :action => 'edit'
31
    end
32
  end
33

  
34
  def destroy
35
    @media = Media.find(params[:id])
36
    @media.destroy
37
    flash[:notice] = "Successfully destroyed media."
38
    redirect_to medias_url
39
  end
40
end
app/controllers/unattended_controller.rb
8 8
  def kickstart
9 9
    logger.info "#{controller_name}: Kickstart host #{@host.name}"
10 10
    @dynamic = @host.diskLayout=~/^#Dynamic/
11
    @arch      = @host.architecture.name
12
    os         = @host.operatingsystem
13
    @osver     = os.major.to_i
14
    @mediapath = os.mediapath @host
15
    @epel      = os.epel      @host
16
    @yumrepo   = os.yumrepo   @host
11
    @arch       = @host.architecture.name
12
    os          = @host.operatingsystem
13
    @osver      = os.major.to_i
14
    @mediumpath = os.mediumpath @host
15
    @epel       = os.epel       @host
16
    @yumrepo    = os.yumrepo    @host
17 17
    unattended_local "kickstart"
18 18
  end
19 19

  
......
61 61
    end
62 62

  
63 63
    conditions = (mac and ip) ? ["mac = ? and ip = ?",mac, ip] : ["ip = ?",ip];
64
    @host = Host.find(:first, :include => [:architecture, :media, :operatingsystem, :domain], :conditions => conditions)
64
    @host = Host.find(:first, :include => [:architecture, :medium, :operatingsystem, :domain], :conditions => conditions)
65 65
    if @host.nil?
66 66
      logger.info "#{controller_name}: unable to find #{ip}#{"/"+mac unless mac.nil?}"
67 67
      head(:not_found) and return
app/helpers/medias_helper.rb
1
module MediasHelper
2
end
app/helpers/medium_helper.rb
1
module MediumHelper
2
end
app/models/host.rb
1 1
class Host < Puppet::Rails::Host
2 2
  belongs_to :architecture
3
  belongs_to :media
3
  belongs_to :medium
4 4
  belongs_to :model
5 5
  belongs_to :domain
6 6
  belongs_to :operatingsystem
......
76 76
    validates_format_of      :sp_mac,    :with => /([a-f0-9]{1,2}:){5}[a-f0-9]{1,2}/, :allow_nil => true, :allow_blank => true
77 77
    validates_format_of      :sp_ip,     :with => /(\d{1,3}\.){3}\d{1,3}/, :allow_nil => true, :allow_blank => true
78 78
    validates_format_of      :serial,    :with => /[01],\d{3,}n\d/, :message => "should follow this format: 0,9600n8", :allow_blank => true, :allow_nil => true
79
    validates_associated     :domain, :operatingsystem,  :architecture, :subnet,:media#, :user, :deployment, :model
79
    validates_associated     :domain, :operatingsystem,  :architecture, :subnet,:medium #, :user, :deployment, :model
80 80
  end
81 81

  
82 82
  before_validation :normalize_addresses, :normalize_hostname
app/models/media.rb
1
class Media < ActiveRecord::Base
2
  belongs_to :operatingsystem
3
  has_many :hosts
4
  validates_uniqueness_of :name, :scope => :operatingsystem_id
5
  validates_uniqueness_of :path, :scope => :operatingsystem_id
6
  validates_presence_of :name, :path
7
  validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces."
8
  validates_format_of :path, :with => /^(http|https|ftp|nfs):\/\//,
9
    :message => "Only URLs with schema http://, https://, ftp:// or nfs:// are allowed (e.g. nfs://server/vol/dir)"
10

  
11
  alias_attribute :os, :operatingsystem
12
  before_destroy Ensure_not_used_by.new(:hosts)
13

  
14
  def to_s
15
    name
16
  end
17

  
18
end
app/models/medium.rb
1
class Medium < ActiveRecord::Base
2
  belongs_to :operatingsystem
3
  has_many :hosts
4
  validates_uniqueness_of :name, :scope => :operatingsystem_id
5
  validates_uniqueness_of :path, :scope => :operatingsystem_id
6
  validates_presence_of :name, :path
7
  validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces."
8
  validates_format_of :path, :with => /^(http|https|ftp|nfs):\/\//,
9
    :message => "Only URLs with schema http://, https://, ftp:// or nfs:// are allowed (e.g. nfs://server/vol/dir)"
10

  
11
  alias_attribute :os, :operatingsystem
12
  before_destroy Ensure_not_used_by.new(:hosts)
13

  
14
  def to_s
15
    name
16
  end
17

  
18
end
app/models/operatingsystem.rb
1 1
class Operatingsystem < ActiveRecord::Base
2 2
  has_many :hosts
3
  has_many :medias
3
  has_many :media
4 4
  has_and_belongs_to_many :ptables
5 5
  has_and_belongs_to_many :architectures
6 6
  has_and_belongs_to_many :puppetclasses
app/views/home/settings.erb
4 4
    <li><%= link_to 'Host Groups',        hostgroups_path %>         </li>
5 5
    <li><%= link_to 'Domains',            domains_path %>            </li>
6 6
    <li><%= link_to 'Operating Systems',  operatingsystems_path %>   </li>
7
    <li><%= link_to 'Installation Medias',medias_path %>             </li>
7
    <li><%= link_to 'Installation Media', media_path %>              </li>
8 8
    <li><%= link_to 'Hardware Models',    models_path %>             </li>
9 9
    <li><%= link_to 'Environments',       environments_path %>       </li>
10 10
    <li><%= link_to 'Architectures',      architectures_path %>      </li>
app/views/hosts/_operatingsystem.html.erb
1 1
Media
2
<%= collection_select :host, :media_id, @operatingsystem.medias, :id, :to_label %>
2
<%= collection_select :host, :medium_id, @operatingsystem.media, :id, :to_label %>
3 3
Partition Table
4 4
<%= collection_select :host, :ptable_id, @operatingsystem.ptables, :id, :to_label %>
app/views/media/_form.html.erb
1
<% form_for @medium do |f| %>
2
  <%= f.error_messages %>
3
  <p>
4
  <%= f.label :name %><br />
5
  <%= f.text_field :name %>
6
  </p>
7
  <p>
8
  <%= f.label :path %><br />
9
  <%= f.text_field :path %>
10
  </p >
11
  <small>
12
    The path to the medium, can be a URL or a valid NFS server (exclusive of the architecture).<br />
13
    for example http://mirror.averse.net/centos/$version/os/$arch where <strong>$arch</strong> will be substituted for the host's actual OS architecture<br />
14
    and <strong>$version</strong>, <strong>$major</strong> and <strong>$minor</strong> will be substituted for the version of the operating system.
15
  </small>
16
  <p>
17
  <%= f.label :operatingsystem_id %><br />
18
  <%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %>
19
  </p>
20
  <% unless @medium.new_record? -%>
21
    <p>Currently used by <%= @medium.hosts.count %> hosts</p>
22
  <% end -%>
23

  
24
  <p><%= f.submit "Submit" %></p>
25
<% end %>
app/views/media/edit.html.erb
1
<% title "Edit Medium" %>
2

  
3
<%= render :partial => 'form' %>
4

  
5
<p>
6
  <%= link_to "View All", media_path %>
7
</p>
app/views/media/index.html.erb
1
<% title "Installation Media" %>
2

  
3
<table class="list">
4
  <tr>
5
    <th>Name</th>
6
    <th>Path</th>
7
    <th>Operating system</th>
8
  </tr>
9
  <% for medium in @media %>
10
    <tr>
11
      <td><%= link_to h(medium), edit_medium_path(medium) %></td>
12
      <td><%=h medium.path %></td>
13
      <td><%=h medium.operatingsystem %></td>
14
      <td><%= link_to "Destroy", medium, :confirm => 'Are you sure?', :method => :delete %></td>
15
    </tr>
16
  <% end %>
17
</table>
18

  
19
<p><%= link_to "New Medium", new_medium_path %></p>
app/views/media/new.html.erb
1
<% title "New Medium" %>
2

  
3
<%= render :partial => 'form' %>
4

  
5
<p><%= link_to "Back to List", media_path %></p>
app/views/medias/_form.html.erb
1
<% form_for @media do |f| %>
2
  <%= f.error_messages %>
3
  <p>
4
  <%= f.label :name %><br />
5
  <%= f.text_field :name %>
6
  </p>
7
  <p>
8
  <%= f.label :path %><br />
9
  <%= f.text_field :path %>
10
  </p >
11
  <small>
12
    The path to the media, can be a URL or a valid NFS server (exclusive of the architecture).<br />
13
    for example http://mirror.averse.net/centos/$version/os/$arch where <strong>$arch</strong> will be substituted for the host's actual OS architecture<br />
14
    and <strong>$version</strong>, <strong>$major</strong> and <strong>$minor</strong> will be substituted for the version of the operating system.
15
  </small>
16
  <p>
17
  <%= f.label :operatingsystem_id %><br />
18
  <%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %>
19
  </p>
20
  <% unless @media.new_record? -%>
21
    <p>Currently used by <%= @media.hosts.count %> hosts</p>
22
  <% end -%>
23

  
24
  <p><%= f.submit "Submit" %></p>
25
<% end %>
app/views/medias/edit.html.erb
1
<% title "Edit Media" %>
2

  
3
<%= render :partial => 'form' %>
4

  
5
<p>
6
  <%= link_to "View All", medias_path %>
7
</p>
app/views/medias/index.html.erb
1
<% title "Medias" %>
2

  
3
<table class="list">
4
  <tr>
5
    <th>Name</th>
6
    <th>Path</th>
7
    <th>Operatingsystem</th>
8
  </tr>
9
  <% for media in @medias %>
10
    <tr>
11
      <td><%= link_to h(media), edit_media_path(media) %></td>
12
      <td><%=h media.path %></td>
13
      <td><%=h media.operatingsystem %></td>
14
      <td><%= link_to "Destroy", media, :confirm => 'Are you sure?', :method => :delete %></td>
15
    </tr>
16
  <% end %>
17
</table>
18

  
19
<p><%= link_to "New Media", new_media_path %></p>
app/views/medias/new.html.erb
1
<% title "New Media" %>
2

  
3
<%= render :partial => 'form' %>
4

  
5
<p><%= link_to "Back to List", medias_path %></p>
app/views/operatingsystems/_form.html.erb
21 21
  <% end -%>
22 22
  </p>
23 23
  <p>
24
  <% field_set_tag("Installation Medias") do %>
25
    <%= edit_habtm @operatingsystem, Media %>
24
  <% field_set_tag("Installation Media") do %>
25
    <%= edit_habtm @operatingsystem, Medium %>
26 26
  <% end -%>
27 27
  </p>
28 28

  
app/views/unattended/kickstart.rhtml
1 1
install
2
<%= @mediapath %>
2
<%= @mediumpath %>
3 3
lang en_US.UTF-8
4 4
<%= "langsupport --default en_US.UTF-8 en_GB.UTF-8 en_US.UTF-8\n" if @osver < 5 -%>
5 5
<%= "mouse generic3usb --device input/mice\n" if @osver == 3 -%>
config/routes.rb
24 24
  map.connect   "/lookup", :controller => "lookup_keys", :action => "q"
25 25
  map.resources :domains
26 26
  map.resources :operatingsystems
27
  map.resources :medias
27
  map.resources :media
28 28
  map.resources :models
29 29
  map.resources :architectures
30 30
  map.resources :puppetclasses, :member => { :assign => :post }, :collection => {:import_environments => :get}
db/migrate/20100523075526_drop_medias.rb
1
class DropMedias < ActiveRecord::Migration
2
  def self.up
3
    drop_table :medias
4
  end
5

  
6
  def self.down
7
    create_table :medias do |t|
8
      t.string :name, :limit => 50, :default => "", :null => false
9
      t.string :path, :limit => 100, :default => "", :null => false
10
      t.references :operatingsystem
11
      t.timestamps
12
    end
13
    Media.create :name => "CentOS 5 mirror", :path => "http://mirror.averse.net/centos/5.3/os/$arch"
14
    Media.create :name => "Fedora 11 Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/11/Fedora/$arch/os/"
15
  end
16
end
db/migrate/20100523075701_create_media.rb
1
class CreateMedia < ActiveRecord::Migration
2
  def self.up
3
    create_table :media do |t|
4
      t.string :name, :limit => 50, :default => "", :null => false
5
      t.string :path, :limit => 100, :default => "", :null => false
6
      t.references :operatingsystem
7
      t.timestamps
8
    end
9
    Medium.create :name => "CentOS 5 mirror", :path => "http://mirror.averse.net/centos/5.3/os/$arch"
10
    Medium.create :name => "Fedora 11 Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/11/Fedora/$arch/os/"
11
  end
12

  
13
  def self.down
14
    drop_table :media
15
  end
16
end
db/migrate/20100523080255_remove_index_from_host.rb
1
class RemoveIndexFromHost < ActiveRecord::Migration
2
  def self.up
3
    remove_index "hosts", :name => 'host_media_id_ix'
4
  end
5

  
6
  def self.down
7
    add_index "hosts", :media_id, :name => 'host_media_id_ix'
8
  end
9
end
db/migrate/20100523080316_change_host_media_id.rb
1
class ChangeHostMediaId < ActiveRecord::Migration
2
  def self.up
3
    change_table :hosts do |t|
4
      t.rename :media_id, :medium_id 
5
    end 
6
  end
7

  
8
  def self.down
9
    change_table :hosts do |t|
10
      t.rename :medium_id, :media_id
11
    end 
12
  end
13
end
db/migrate/20100523080344_add_index_media_id_to_host.rb
1
class AddIndexMediaIdToHost < ActiveRecord::Migration
2
  def self.up
3
    add_index "hosts", :medium_id, :name => 'host_medium_id_ix'
4
  end
5

  
6
  def self.down
7
    remove_index "hosts", :name => 'host_medium_id_ix'
8
  end
9
end
lib/family.rb
14 14
    FAMILIES.map{|e| OpenStruct.new(:name => e, :value => FAMILIES.index(e)) }
15 15
  end
16 16

  
17
  def media_uri host, url = nil
18
    url ||= host.media.path
17
  def medium_uri host, url = nil
18
    url ||= host.medium.path
19 19
    URI.parse(url.gsub('$arch',host.architecture.name).
20 20
                  gsub('$major', host.os.major).
21 21
                  gsub('$minor', host.os.minor).
......
27 27
    include Family
28 28

  
29 29
    def preseed_server host
30
      media_uri(host).select(:host, :port).compact.join(':')
30
      medium_uri(host).select(:host, :port).compact.join(':')
31 31
    end
32 32

  
33 33
    def preseed_path host
34
      media_uri(host).select(:path, :query).compact.join('?')
34
      medium_uri(host).select(:path, :query).compact.join('?')
35 35
    end
36 36
  end
37 37

  
38 38
  module RedHat
39 39
    include Family
40
    # outputs kickstart installation media based on the media type (NFS or URL)
40
    # outputs kickstart installation medium based on the medium type (NFS or URL)
41 41
    # it also convert the $arch string to the current host architecture
42
    def mediapath host
43
      uri = media_uri(host)
42
    def mediumpath host
43
      uri = medium_uri(host)
44 44
      server = uri.select(:host, :port).compact.join(':')
45 45
      dir = uri.select(:path, :query).compact.join('?') unless uri.scheme == 'ftp'
46 46

  
......
67 67
      else
68 68
        return ""
69 69
      end
70
      return "su -c 'rpm -Uvh #{media_uri(host, epel_url)}'"
70
      return "su -c 'rpm -Uvh #{medium_uri(host, epel_url)}'"
71 71
    end
72 72

  
73 73
    def yumrepo host
test/fixtures/media.yml
1
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2

  
3
one:
4
  name: CentOS 5.4
5
  path: http://mirror.averse.net/centos/6.0/os/$arch
6
  operatingsystem_id: 1
test/fixtures/medias.yml
1
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2

  
3
one:
4
  name: CentOS 5.4
5
  path: http://mirror.averse.net/centos/6.0/os/$arch
6
  operatingsystem_id: 1
test/functional/media_controller_test.rb
1
require 'test_helper'
2

  
3
class MediaControllerTest < ActionController::TestCase
4
  def test_index
5
    get :index, {}, set_session_user
6
    assert_template 'index'
7
  end
8

  
9
  def test_new
10
    get :new, {}, set_session_user
11
    assert_template 'new'
12
  end
13

  
14
  def test_create_invalid
15
    Medium.any_instance.stubs(:valid?).returns(false)
16
    post :create, {}, set_session_user
17
    assert_template 'new'
18
  end
19

  
20
  def test_create_valid
21
    Medium.any_instance.stubs(:valid?).returns(true)
22
    post :create, {}, set_session_user
23
    assert_redirected_to media_url
24
  end
25

  
26
  def test_edit
27
    get :edit, {:id => Medium.first}, set_session_user
28
    assert_template 'edit'
29
  end
30

  
31
  def test_update_invalid
32
    Medium.any_instance.stubs(:valid?).returns(false)
33
    put :update, {:id => Medium.first}, set_session_user
34
    assert_template 'edit'
35
  end
36

  
37
  def test_update_valid
38
    Medium.any_instance.stubs(:valid?).returns(true)
39
    put :update, {:id => Medium.first}, set_session_user
40
    assert_redirected_to media_url
41
  end
42

  
43
  def test_destroy
44
    medium = Medium.first
45
    delete :destroy, {:id => medium}, set_session_user
46
    assert_redirected_to media_url
47
    assert !Medium.exists?(medium.id)
48
  end
49
end
test/functional/medias_controller_test.rb
1
require 'test_helper'
2

  
3
class MediasControllerTest < ActionController::TestCase
4
  def test_index
5
    get :index, {}, set_session_user
6
    assert_template 'index'
7
  end
8

  
9
  def test_new
10
    get :new, {}, set_session_user
11
    assert_template 'new'
12
  end
13

  
14
  def test_create_invalid
15
    Media.any_instance.stubs(:valid?).returns(false)
16
    post :create, {}, set_session_user
17
    assert_template 'new'
18
  end
19

  
20
  def test_create_valid
21
    Media.any_instance.stubs(:valid?).returns(true)
22
    post :create, {}, set_session_user
23
    assert_redirected_to medias_url
24
  end
25

  
26
  def test_edit
27
    get :edit, {:id => Media.first}, set_session_user
28
    assert_template 'edit'
29
  end
30

  
31
  def test_update_invalid
32
    Media.any_instance.stubs(:valid?).returns(false)
33
    put :update, {:id => Media.first}, set_session_user
34
    assert_template 'edit'
35
  end
36

  
37
  def test_update_valid
38
    Media.any_instance.stubs(:valid?).returns(true)
39
    put :update, {:id => Media.first}, set_session_user
40
    assert_redirected_to medias_url
41
  end
42

  
43
  def test_destroy
44
    media = Media.first
45
    delete :destroy, {:id => media}, set_session_user
46
    assert_redirected_to medias_url
47
    assert !Media.exists?(media.id)
48
  end
49
end
test/unit/helpers/media_helper_test.rb
1
require 'test_helper'
2

  
3
class MediaHelperTest < ActionView::TestCase
4
end
test/unit/helpers/medium_helper_test.rb
1
require 'test_helper'
2

  
3
class MediumHelperTest < ActionView::TestCase
4
end
test/unit/media_test.rb
1
require 'test_helper'
2

  
3
class MediaTest < ActiveSupport::TestCase
4
  test "name can't be blank" do
5
    media = Media.new :name => "   ", :path => "http://www.google.com"
6
    assert media.name.strip.empty?
7
    assert !media.save
8
  end
9

  
10
  test "name can't contain white spaces" do
11
    media = Media.new :name => "   Archlinux mirror   thing   ", :path => "http://www.google.com"
12
    assert !media.name.strip.squeeze(" ").empty?
13
    assert !media.save
14

  
15
    media.name.strip!.squeeze!(" ")
16
    assert media.save!
17
  end
18

  
19
  test "name must be unique" do
20
    media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com"
21
    assert media.save!
22

  
23
    other_media = Media.new :name => "Archlinux mirror", :path => "http://www.youtube.com"
24
    assert !other_media.save
25
  end
26

  
27
  test "path can't be blank" do
28
    media = Media.new :name => "Archlinux mirror", :path => "  "
29
    assert media.path.strip.empty?
30
    assert !media.save
31
  end
32

  
33
  test "path must be unique" do
34
    media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com"
35
    assert media.save!
36

  
37
    other_media = Media.new :name => "Ubuntu mirror", :path => "http://www.google.com"
38
    assert !other_media.save
39
  end
40

  
41
  test "should not destroy while using" do
42
    media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com"
43
    assert media.save!
44

  
45
    host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
46
      :domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first,
47
      :architecture => Architecture.first, :environment => Environment.first, :disk => "empty partition",
48
      :ptable => Ptable.first
49
    assert host.save!
50

  
51
    media.hosts << host
52

  
53
    assert !media.destroy
54
  end
55
end
test/unit/medium_test.rb
1
require 'test_helper'
2

  
3
class MediumTest < ActiveSupport::TestCase
4
  test "name can't be blank" do
5
    medium = Medium.new :name => "   ", :path => "http://www.google.com"
6
    assert medium.name.strip.empty?
7
    assert !medium.save
8
  end
9

  
10
  test "name can't contain white spaces" do
11
    medium = Medium.new :name => "   Archlinux mirror   thing   ", :path => "http://www.google.com"
12
    assert !medium.name.strip.squeeze(" ").empty?
13
    assert !medium.save
14

  
15
    medium.name.strip!.squeeze!(" ")
16
    assert medium.save!
17
  end
18

  
19
  test "name must be unique" do
20
    medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com"
21
    assert medium.save!
22

  
23
    other_medium = Medium.new :name => "Archlinux mirror", :path => "http://www.youtube.com"
24
    assert !other_medium.save
25
  end
26

  
27
  test "path can't be blank" do
28
    medium = Medium.new :name => "Archlinux mirror", :path => "  "
29
    assert medium.path.strip.empty?
30
    assert !medium.save
31
  end
32

  
33
  test "path must be unique" do
34
    medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com"
35
    assert medium.save!
36

  
37
    other_medium = Medium.new :name => "Ubuntu mirror", :path => "http://www.google.com"
38
    assert !other_medium.save
39
  end
40

  
41
  test "should not destroy while using" do
42
    medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com"
43
    assert medium.save!
44

  
45
    host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03",
46
      :domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first,
47
      :architecture => Architecture.first, :environment => Environment.first, :disk => "empty partition",
48
      :ptable => Ptable.first
49
    assert host.save!
50

  
51
    medium.hosts << host
52

  
53
    assert !medium.destroy
54
  end
55
end
0
-