From f9eb15f30cc3360daa7dd418f79a1ea353a7e347 Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Sun, 23 May 2010 08:21:13 +0000 Subject: [PATCH] Fixes #263 - correct pluralization of medium, media. --- app/controllers/media_controller.rb | 40 ++++++++++++++ app/controllers/medias_controller.rb | 40 -------------- app/controllers/unattended_controller.rb | 14 +++--- app/helpers/medias_helper.rb | 2 - app/helpers/medium_helper.rb | 2 + app/models/host.rb | 4 +- app/models/media.rb | 18 ------ app/models/medium.rb | 18 ++++++ app/models/operatingsystem.rb | 2 +- app/views/home/settings.erb | 2 +- app/views/hosts/_operatingsystem.html.erb | 2 +- app/views/media/_form.html.erb | 25 +++++++++ app/views/media/edit.html.erb | 7 +++ app/views/media/index.html.erb | 19 +++++++ app/views/media/new.html.erb | 5 ++ app/views/medias/_form.html.erb | 25 --------- app/views/medias/edit.html.erb | 7 --- app/views/medias/index.html.erb | 19 ------- app/views/medias/new.html.erb | 5 -- app/views/operatingsystems/_form.html.erb | 4 +- app/views/unattended/kickstart.rhtml | 2 +- config/routes.rb | 2 +- db/migrate/20100523075526_drop_medias.rb | 16 ++++++ db/migrate/20100523075701_create_media.rb | 16 ++++++ .../20100523080255_remove_index_from_host.rb | 9 +++ db/migrate/20100523080316_change_host_media_id.rb | 13 +++++ .../20100523080344_add_index_media_id_to_host.rb | 9 +++ lib/family.rb | 16 +++--- test/fixtures/media.yml | 6 ++ test/fixtures/medias.yml | 6 -- test/functional/media_controller_test.rb | 49 +++++++++++++++++ test/functional/medias_controller_test.rb | 49 ----------------- test/unit/helpers/media_helper_test.rb | 4 -- test/unit/helpers/medium_helper_test.rb | 4 ++ test/unit/media_test.rb | 55 -------------------- test/unit/medium_test.rb | 55 ++++++++++++++++++++ 36 files changed, 317 insertions(+), 254 deletions(-) create mode 100644 app/controllers/media_controller.rb delete mode 100644 app/controllers/medias_controller.rb delete mode 100644 app/helpers/medias_helper.rb create mode 100644 app/helpers/medium_helper.rb delete mode 100644 app/models/media.rb create mode 100644 app/models/medium.rb create mode 100644 app/views/media/_form.html.erb create mode 100644 app/views/media/edit.html.erb create mode 100644 app/views/media/index.html.erb create mode 100644 app/views/media/new.html.erb delete mode 100644 app/views/medias/_form.html.erb delete mode 100644 app/views/medias/edit.html.erb delete mode 100644 app/views/medias/index.html.erb delete mode 100644 app/views/medias/new.html.erb create mode 100644 db/migrate/20100523075526_drop_medias.rb create mode 100644 db/migrate/20100523075701_create_media.rb create mode 100644 db/migrate/20100523080255_remove_index_from_host.rb create mode 100644 db/migrate/20100523080316_change_host_media_id.rb create mode 100644 db/migrate/20100523080344_add_index_media_id_to_host.rb create mode 100644 test/fixtures/media.yml delete mode 100644 test/fixtures/medias.yml create mode 100644 test/functional/media_controller_test.rb delete mode 100644 test/functional/medias_controller_test.rb delete mode 100644 test/unit/helpers/media_helper_test.rb create mode 100644 test/unit/helpers/medium_helper_test.rb delete mode 100644 test/unit/media_test.rb create mode 100644 test/unit/medium_test.rb diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb new file mode 100644 index 0000000..f032380 --- /dev/null +++ b/app/controllers/media_controller.rb @@ -0,0 +1,40 @@ +class MediaController < ApplicationController + def index + @media = Medium.all(:include => [:operatingsystem]) + end + + def new + @medium = Medium.new + end + + def create + @medium = Medium.new(params[:medium]) + if @medium.save + flash[:notice] = "Successfully created medium." + redirect_to media_url + else + render :action => 'new' + end + end + + def edit + @medium = Medium.find(params[:id]) + end + + def update + @medium = Medium.find(params[:id]) + if @medium.update_attributes(params[:medium]) + flash[:notice] = "Successfully updated medium." + redirect_to media_url + else + render :action => 'edit' + end + end + + def destroy + @medium = Medium.find(params[:id]) + @medium.destroy + flash[:notice] = "Successfully destroyed medium." + redirect_to media_url + end +end diff --git a/app/controllers/medias_controller.rb b/app/controllers/medias_controller.rb deleted file mode 100644 index cf0340e..0000000 --- a/app/controllers/medias_controller.rb +++ /dev/null @@ -1,40 +0,0 @@ -class MediasController < ApplicationController - def index - @medias = Media.all(:include => [:operatingsystem]) - end - - def new - @media = Media.new - end - - def create - @media = Media.new(params[:media]) - if @media.save - flash[:notice] = "Successfully created media." - redirect_to medias_url - else - render :action => 'new' - end - end - - def edit - @media = Media.find(params[:id]) - end - - def update - @media = Media.find(params[:id]) - if @media.update_attributes(params[:media]) - flash[:notice] = "Successfully updated media." - redirect_to medias_url - else - render :action => 'edit' - end - end - - def destroy - @media = Media.find(params[:id]) - @media.destroy - flash[:notice] = "Successfully destroyed media." - redirect_to medias_url - end -end diff --git a/app/controllers/unattended_controller.rb b/app/controllers/unattended_controller.rb index 4d79935..ceaa2a1 100644 --- a/app/controllers/unattended_controller.rb +++ b/app/controllers/unattended_controller.rb @@ -8,12 +8,12 @@ class UnattendedController < ApplicationController def kickstart logger.info "#{controller_name}: Kickstart host #{@host.name}" @dynamic = @host.diskLayout=~/^#Dynamic/ - @arch = @host.architecture.name - os = @host.operatingsystem - @osver = os.major.to_i - @mediapath = os.mediapath @host - @epel = os.epel @host - @yumrepo = os.yumrepo @host + @arch = @host.architecture.name + os = @host.operatingsystem + @osver = os.major.to_i + @mediumpath = os.mediumpath @host + @epel = os.epel @host + @yumrepo = os.yumrepo @host unattended_local "kickstart" end @@ -61,7 +61,7 @@ class UnattendedController < ApplicationController end conditions = (mac and ip) ? ["mac = ? and ip = ?",mac, ip] : ["ip = ?",ip]; - @host = Host.find(:first, :include => [:architecture, :media, :operatingsystem, :domain], :conditions => conditions) + @host = Host.find(:first, :include => [:architecture, :medium, :operatingsystem, :domain], :conditions => conditions) if @host.nil? logger.info "#{controller_name}: unable to find #{ip}#{"/"+mac unless mac.nil?}" head(:not_found) and return diff --git a/app/helpers/medias_helper.rb b/app/helpers/medias_helper.rb deleted file mode 100644 index e0f0d29..0000000 --- a/app/helpers/medias_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module MediasHelper -end diff --git a/app/helpers/medium_helper.rb b/app/helpers/medium_helper.rb new file mode 100644 index 0000000..1ae76c4 --- /dev/null +++ b/app/helpers/medium_helper.rb @@ -0,0 +1,2 @@ +module MediumHelper +end diff --git a/app/models/host.rb b/app/models/host.rb index 88c4698..14c9fe2 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -1,6 +1,6 @@ class Host < Puppet::Rails::Host belongs_to :architecture - belongs_to :media + belongs_to :medium belongs_to :model belongs_to :domain belongs_to :operatingsystem @@ -76,7 +76,7 @@ class Host < Puppet::Rails::Host validates_format_of :sp_mac, :with => /([a-f0-9]{1,2}:){5}[a-f0-9]{1,2}/, :allow_nil => true, :allow_blank => true validates_format_of :sp_ip, :with => /(\d{1,3}\.){3}\d{1,3}/, :allow_nil => true, :allow_blank => true validates_format_of :serial, :with => /[01],\d{3,}n\d/, :message => "should follow this format: 0,9600n8", :allow_blank => true, :allow_nil => true - validates_associated :domain, :operatingsystem, :architecture, :subnet,:media#, :user, :deployment, :model + validates_associated :domain, :operatingsystem, :architecture, :subnet,:medium #, :user, :deployment, :model end before_validation :normalize_addresses, :normalize_hostname diff --git a/app/models/media.rb b/app/models/media.rb deleted file mode 100644 index 6026e3a..0000000 --- a/app/models/media.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Media < ActiveRecord::Base - belongs_to :operatingsystem - has_many :hosts - validates_uniqueness_of :name, :scope => :operatingsystem_id - validates_uniqueness_of :path, :scope => :operatingsystem_id - validates_presence_of :name, :path - validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces." - validates_format_of :path, :with => /^(http|https|ftp|nfs):\/\//, - :message => "Only URLs with schema http://, https://, ftp:// or nfs:// are allowed (e.g. nfs://server/vol/dir)" - - alias_attribute :os, :operatingsystem - before_destroy Ensure_not_used_by.new(:hosts) - - def to_s - name - end - -end diff --git a/app/models/medium.rb b/app/models/medium.rb new file mode 100644 index 0000000..94b484e --- /dev/null +++ b/app/models/medium.rb @@ -0,0 +1,18 @@ +class Medium < ActiveRecord::Base + belongs_to :operatingsystem + has_many :hosts + validates_uniqueness_of :name, :scope => :operatingsystem_id + validates_uniqueness_of :path, :scope => :operatingsystem_id + validates_presence_of :name, :path + validates_format_of :name, :with => /\A(\S+\s?)+\Z/, :message => "can't be blank or contain trailing white spaces." + validates_format_of :path, :with => /^(http|https|ftp|nfs):\/\//, + :message => "Only URLs with schema http://, https://, ftp:// or nfs:// are allowed (e.g. nfs://server/vol/dir)" + + alias_attribute :os, :operatingsystem + before_destroy Ensure_not_used_by.new(:hosts) + + def to_s + name + end + +end diff --git a/app/models/operatingsystem.rb b/app/models/operatingsystem.rb index a100faf..5bfc875 100644 --- a/app/models/operatingsystem.rb +++ b/app/models/operatingsystem.rb @@ -1,6 +1,6 @@ class Operatingsystem < ActiveRecord::Base has_many :hosts - has_many :medias + has_many :media has_and_belongs_to_many :ptables has_and_belongs_to_many :architectures has_and_belongs_to_many :puppetclasses diff --git a/app/views/home/settings.erb b/app/views/home/settings.erb index 9370725..c683e6d 100644 --- a/app/views/home/settings.erb +++ b/app/views/home/settings.erb @@ -4,7 +4,7 @@
  • <%= link_to 'Host Groups', hostgroups_path %>
  • <%= link_to 'Domains', domains_path %>
  • <%= link_to 'Operating Systems', operatingsystems_path %>
  • -
  • <%= link_to 'Installation Medias',medias_path %>
  • +
  • <%= link_to 'Installation Media', media_path %>
  • <%= link_to 'Hardware Models', models_path %>
  • <%= link_to 'Environments', environments_path %>
  • <%= link_to 'Architectures', architectures_path %>
  • diff --git a/app/views/hosts/_operatingsystem.html.erb b/app/views/hosts/_operatingsystem.html.erb index e08ab18..6f32ae2 100644 --- a/app/views/hosts/_operatingsystem.html.erb +++ b/app/views/hosts/_operatingsystem.html.erb @@ -1,4 +1,4 @@ Media -<%= collection_select :host, :media_id, @operatingsystem.medias, :id, :to_label %> +<%= collection_select :host, :medium_id, @operatingsystem.media, :id, :to_label %> Partition Table <%= collection_select :host, :ptable_id, @operatingsystem.ptables, :id, :to_label %> diff --git a/app/views/media/_form.html.erb b/app/views/media/_form.html.erb new file mode 100644 index 0000000..4b31413 --- /dev/null +++ b/app/views/media/_form.html.erb @@ -0,0 +1,25 @@ +<% form_for @medium do |f| %> + <%= f.error_messages %> +

    + <%= f.label :name %>
    + <%= f.text_field :name %> +

    +

    + <%= f.label :path %>
    + <%= f.text_field :path %> +

    + + The path to the medium, can be a URL or a valid NFS server (exclusive of the architecture).
    + for example http://mirror.averse.net/centos/$version/os/$arch where $arch will be substituted for the host's actual OS architecture
    + and $version, $major and $minor will be substituted for the version of the operating system. +
    +

    + <%= f.label :operatingsystem_id %>
    + <%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %> +

    + <% unless @medium.new_record? -%> +

    Currently used by <%= @medium.hosts.count %> hosts

    + <% end -%> + +

    <%= f.submit "Submit" %>

    +<% end %> diff --git a/app/views/media/edit.html.erb b/app/views/media/edit.html.erb new file mode 100644 index 0000000..100d7c3 --- /dev/null +++ b/app/views/media/edit.html.erb @@ -0,0 +1,7 @@ +<% title "Edit Medium" %> + +<%= render :partial => 'form' %> + +

    + <%= link_to "View All", media_path %> +

    diff --git a/app/views/media/index.html.erb b/app/views/media/index.html.erb new file mode 100644 index 0000000..08f2eec --- /dev/null +++ b/app/views/media/index.html.erb @@ -0,0 +1,19 @@ +<% title "Installation Media" %> + + + + + + + + <% for medium in @media %> + + + + + + + <% end %> +
    NamePathOperating system
    <%= link_to h(medium), edit_medium_path(medium) %><%=h medium.path %><%=h medium.operatingsystem %><%= link_to "Destroy", medium, :confirm => 'Are you sure?', :method => :delete %>
    + +

    <%= link_to "New Medium", new_medium_path %>

    diff --git a/app/views/media/new.html.erb b/app/views/media/new.html.erb new file mode 100644 index 0000000..0e80f46 --- /dev/null +++ b/app/views/media/new.html.erb @@ -0,0 +1,5 @@ +<% title "New Medium" %> + +<%= render :partial => 'form' %> + +

    <%= link_to "Back to List", media_path %>

    diff --git a/app/views/medias/_form.html.erb b/app/views/medias/_form.html.erb deleted file mode 100644 index ed730dd..0000000 --- a/app/views/medias/_form.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<% form_for @media do |f| %> - <%= f.error_messages %> -

    - <%= f.label :name %>
    - <%= f.text_field :name %> -

    -

    - <%= f.label :path %>
    - <%= f.text_field :path %> -

    - - The path to the media, can be a URL or a valid NFS server (exclusive of the architecture).
    - for example http://mirror.averse.net/centos/$version/os/$arch where $arch will be substituted for the host's actual OS architecture
    - and $version, $major and $minor will be substituted for the version of the operating system. -
    -

    - <%= f.label :operatingsystem_id %>
    - <%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %> -

    - <% unless @media.new_record? -%> -

    Currently used by <%= @media.hosts.count %> hosts

    - <% end -%> - -

    <%= f.submit "Submit" %>

    -<% end %> diff --git a/app/views/medias/edit.html.erb b/app/views/medias/edit.html.erb deleted file mode 100644 index d4ffce0..0000000 --- a/app/views/medias/edit.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% title "Edit Media" %> - -<%= render :partial => 'form' %> - -

    - <%= link_to "View All", medias_path %> -

    diff --git a/app/views/medias/index.html.erb b/app/views/medias/index.html.erb deleted file mode 100644 index b0536d0..0000000 --- a/app/views/medias/index.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% title "Medias" %> - - - - - - - - <% for media in @medias %> - - - - - - - <% end %> -
    NamePathOperatingsystem
    <%= link_to h(media), edit_media_path(media) %><%=h media.path %><%=h media.operatingsystem %><%= link_to "Destroy", media, :confirm => 'Are you sure?', :method => :delete %>
    - -

    <%= link_to "New Media", new_media_path %>

    diff --git a/app/views/medias/new.html.erb b/app/views/medias/new.html.erb deleted file mode 100644 index ea531d9..0000000 --- a/app/views/medias/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<% title "New Media" %> - -<%= render :partial => 'form' %> - -

    <%= link_to "Back to List", medias_path %>

    diff --git a/app/views/operatingsystems/_form.html.erb b/app/views/operatingsystems/_form.html.erb index 9fc2bb9..6480a88 100644 --- a/app/views/operatingsystems/_form.html.erb +++ b/app/views/operatingsystems/_form.html.erb @@ -21,8 +21,8 @@ <% end -%>

    - <% field_set_tag("Installation Medias") do %> - <%= edit_habtm @operatingsystem, Media %> + <% field_set_tag("Installation Media") do %> + <%= edit_habtm @operatingsystem, Medium %> <% end -%>

    diff --git a/app/views/unattended/kickstart.rhtml b/app/views/unattended/kickstart.rhtml index 7a64e65..9f48c76 100644 --- a/app/views/unattended/kickstart.rhtml +++ b/app/views/unattended/kickstart.rhtml @@ -1,5 +1,5 @@ install -<%= @mediapath %> +<%= @mediumpath %> lang en_US.UTF-8 <%= "langsupport --default en_US.UTF-8 en_GB.UTF-8 en_US.UTF-8\n" if @osver < 5 -%> <%= "mouse generic3usb --device input/mice\n" if @osver == 3 -%> diff --git a/config/routes.rb b/config/routes.rb index 3474bc7..2e9e8ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,7 @@ ActionController::Routing::Routes.draw do |map| map.connect "/lookup", :controller => "lookup_keys", :action => "q" map.resources :domains map.resources :operatingsystems - map.resources :medias + map.resources :media map.resources :models map.resources :architectures map.resources :puppetclasses, :member => { :assign => :post }, :collection => {:import_environments => :get} diff --git a/db/migrate/20100523075526_drop_medias.rb b/db/migrate/20100523075526_drop_medias.rb new file mode 100644 index 0000000..d22fb20 --- /dev/null +++ b/db/migrate/20100523075526_drop_medias.rb @@ -0,0 +1,16 @@ +class DropMedias < ActiveRecord::Migration + def self.up + drop_table :medias + end + + def self.down + create_table :medias do |t| + t.string :name, :limit => 50, :default => "", :null => false + t.string :path, :limit => 100, :default => "", :null => false + t.references :operatingsystem + t.timestamps + end + Media.create :name => "CentOS 5 mirror", :path => "http://mirror.averse.net/centos/5.3/os/$arch" + Media.create :name => "Fedora 11 Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/11/Fedora/$arch/os/" + end +end diff --git a/db/migrate/20100523075701_create_media.rb b/db/migrate/20100523075701_create_media.rb new file mode 100644 index 0000000..4510057 --- /dev/null +++ b/db/migrate/20100523075701_create_media.rb @@ -0,0 +1,16 @@ +class CreateMedia < ActiveRecord::Migration + def self.up + create_table :media do |t| + t.string :name, :limit => 50, :default => "", :null => false + t.string :path, :limit => 100, :default => "", :null => false + t.references :operatingsystem + t.timestamps + end + Medium.create :name => "CentOS 5 mirror", :path => "http://mirror.averse.net/centos/5.3/os/$arch" + Medium.create :name => "Fedora 11 Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/11/Fedora/$arch/os/" + end + + def self.down + drop_table :media + end +end diff --git a/db/migrate/20100523080255_remove_index_from_host.rb b/db/migrate/20100523080255_remove_index_from_host.rb new file mode 100644 index 0000000..ff95fad --- /dev/null +++ b/db/migrate/20100523080255_remove_index_from_host.rb @@ -0,0 +1,9 @@ +class RemoveIndexFromHost < ActiveRecord::Migration + def self.up + remove_index "hosts", :name => 'host_media_id_ix' + end + + def self.down + add_index "hosts", :media_id, :name => 'host_media_id_ix' + end +end diff --git a/db/migrate/20100523080316_change_host_media_id.rb b/db/migrate/20100523080316_change_host_media_id.rb new file mode 100644 index 0000000..a8721e5 --- /dev/null +++ b/db/migrate/20100523080316_change_host_media_id.rb @@ -0,0 +1,13 @@ +class ChangeHostMediaId < ActiveRecord::Migration + def self.up + change_table :hosts do |t| + t.rename :media_id, :medium_id + end + end + + def self.down + change_table :hosts do |t| + t.rename :medium_id, :media_id + end + end +end diff --git a/db/migrate/20100523080344_add_index_media_id_to_host.rb b/db/migrate/20100523080344_add_index_media_id_to_host.rb new file mode 100644 index 0000000..3be3688 --- /dev/null +++ b/db/migrate/20100523080344_add_index_media_id_to_host.rb @@ -0,0 +1,9 @@ +class AddIndexMediaIdToHost < ActiveRecord::Migration + def self.up + add_index "hosts", :medium_id, :name => 'host_medium_id_ix' + end + + def self.down + remove_index "hosts", :name => 'host_medium_id_ix' + end +end diff --git a/lib/family.rb b/lib/family.rb index f034cb7..0d1f6a4 100644 --- a/lib/family.rb +++ b/lib/family.rb @@ -14,8 +14,8 @@ module Family FAMILIES.map{|e| OpenStruct.new(:name => e, :value => FAMILIES.index(e)) } end - def media_uri host, url = nil - url ||= host.media.path + def medium_uri host, url = nil + url ||= host.medium.path URI.parse(url.gsub('$arch',host.architecture.name). gsub('$major', host.os.major). gsub('$minor', host.os.minor). @@ -27,20 +27,20 @@ module Family include Family def preseed_server host - media_uri(host).select(:host, :port).compact.join(':') + medium_uri(host).select(:host, :port).compact.join(':') end def preseed_path host - media_uri(host).select(:path, :query).compact.join('?') + medium_uri(host).select(:path, :query).compact.join('?') end end module RedHat include Family - # outputs kickstart installation media based on the media type (NFS or URL) + # outputs kickstart installation medium based on the medium type (NFS or URL) # it also convert the $arch string to the current host architecture - def mediapath host - uri = media_uri(host) + def mediumpath host + uri = medium_uri(host) server = uri.select(:host, :port).compact.join(':') dir = uri.select(:path, :query).compact.join('?') unless uri.scheme == 'ftp' @@ -67,7 +67,7 @@ module Family else return "" end - return "su -c 'rpm -Uvh #{media_uri(host, epel_url)}'" + return "su -c 'rpm -Uvh #{medium_uri(host, epel_url)}'" end def yumrepo host diff --git a/test/fixtures/media.yml b/test/fixtures/media.yml new file mode 100644 index 0000000..d10755a --- /dev/null +++ b/test/fixtures/media.yml @@ -0,0 +1,6 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + name: CentOS 5.4 + path: http://mirror.averse.net/centos/6.0/os/$arch + operatingsystem_id: 1 diff --git a/test/fixtures/medias.yml b/test/fixtures/medias.yml deleted file mode 100644 index d10755a..0000000 --- a/test/fixtures/medias.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html - -one: - name: CentOS 5.4 - path: http://mirror.averse.net/centos/6.0/os/$arch - operatingsystem_id: 1 diff --git a/test/functional/media_controller_test.rb b/test/functional/media_controller_test.rb new file mode 100644 index 0000000..78b9e2f --- /dev/null +++ b/test/functional/media_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class MediaControllerTest < ActionController::TestCase + def test_index + get :index, {}, set_session_user + assert_template 'index' + end + + def test_new + get :new, {}, set_session_user + assert_template 'new' + end + + def test_create_invalid + Medium.any_instance.stubs(:valid?).returns(false) + post :create, {}, set_session_user + assert_template 'new' + end + + def test_create_valid + Medium.any_instance.stubs(:valid?).returns(true) + post :create, {}, set_session_user + assert_redirected_to media_url + end + + def test_edit + get :edit, {:id => Medium.first}, set_session_user + assert_template 'edit' + end + + def test_update_invalid + Medium.any_instance.stubs(:valid?).returns(false) + put :update, {:id => Medium.first}, set_session_user + assert_template 'edit' + end + + def test_update_valid + Medium.any_instance.stubs(:valid?).returns(true) + put :update, {:id => Medium.first}, set_session_user + assert_redirected_to media_url + end + + def test_destroy + medium = Medium.first + delete :destroy, {:id => medium}, set_session_user + assert_redirected_to media_url + assert !Medium.exists?(medium.id) + end +end diff --git a/test/functional/medias_controller_test.rb b/test/functional/medias_controller_test.rb deleted file mode 100644 index 04ff7ae..0000000 --- a/test/functional/medias_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class MediasControllerTest < ActionController::TestCase - def test_index - get :index, {}, set_session_user - assert_template 'index' - end - - def test_new - get :new, {}, set_session_user - assert_template 'new' - end - - def test_create_invalid - Media.any_instance.stubs(:valid?).returns(false) - post :create, {}, set_session_user - assert_template 'new' - end - - def test_create_valid - Media.any_instance.stubs(:valid?).returns(true) - post :create, {}, set_session_user - assert_redirected_to medias_url - end - - def test_edit - get :edit, {:id => Media.first}, set_session_user - assert_template 'edit' - end - - def test_update_invalid - Media.any_instance.stubs(:valid?).returns(false) - put :update, {:id => Media.first}, set_session_user - assert_template 'edit' - end - - def test_update_valid - Media.any_instance.stubs(:valid?).returns(true) - put :update, {:id => Media.first}, set_session_user - assert_redirected_to medias_url - end - - def test_destroy - media = Media.first - delete :destroy, {:id => media}, set_session_user - assert_redirected_to medias_url - assert !Media.exists?(media.id) - end -end diff --git a/test/unit/helpers/media_helper_test.rb b/test/unit/helpers/media_helper_test.rb deleted file mode 100644 index e02628b..0000000 --- a/test/unit/helpers/media_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MediaHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/medium_helper_test.rb b/test/unit/helpers/medium_helper_test.rb new file mode 100644 index 0000000..ef1219f --- /dev/null +++ b/test/unit/helpers/medium_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MediumHelperTest < ActionView::TestCase +end diff --git a/test/unit/media_test.rb b/test/unit/media_test.rb deleted file mode 100644 index 89aebf3..0000000 --- a/test/unit/media_test.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'test_helper' - -class MediaTest < ActiveSupport::TestCase - test "name can't be blank" do - media = Media.new :name => " ", :path => "http://www.google.com" - assert media.name.strip.empty? - assert !media.save - end - - test "name can't contain white spaces" do - media = Media.new :name => " Archlinux mirror thing ", :path => "http://www.google.com" - assert !media.name.strip.squeeze(" ").empty? - assert !media.save - - media.name.strip!.squeeze!(" ") - assert media.save! - end - - test "name must be unique" do - media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com" - assert media.save! - - other_media = Media.new :name => "Archlinux mirror", :path => "http://www.youtube.com" - assert !other_media.save - end - - test "path can't be blank" do - media = Media.new :name => "Archlinux mirror", :path => " " - assert media.path.strip.empty? - assert !media.save - end - - test "path must be unique" do - media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com" - assert media.save! - - other_media = Media.new :name => "Ubuntu mirror", :path => "http://www.google.com" - assert !other_media.save - end - - test "should not destroy while using" do - media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com" - assert media.save! - - host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03", - :domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first, - :architecture => Architecture.first, :environment => Environment.first, :disk => "empty partition", - :ptable => Ptable.first - assert host.save! - - media.hosts << host - - assert !media.destroy - end -end diff --git a/test/unit/medium_test.rb b/test/unit/medium_test.rb new file mode 100644 index 0000000..7846b9f --- /dev/null +++ b/test/unit/medium_test.rb @@ -0,0 +1,55 @@ +require 'test_helper' + +class MediumTest < ActiveSupport::TestCase + test "name can't be blank" do + medium = Medium.new :name => " ", :path => "http://www.google.com" + assert medium.name.strip.empty? + assert !medium.save + end + + test "name can't contain white spaces" do + medium = Medium.new :name => " Archlinux mirror thing ", :path => "http://www.google.com" + assert !medium.name.strip.squeeze(" ").empty? + assert !medium.save + + medium.name.strip!.squeeze!(" ") + assert medium.save! + end + + test "name must be unique" do + medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com" + assert medium.save! + + other_medium = Medium.new :name => "Archlinux mirror", :path => "http://www.youtube.com" + assert !other_medium.save + end + + test "path can't be blank" do + medium = Medium.new :name => "Archlinux mirror", :path => " " + assert medium.path.strip.empty? + assert !medium.save + end + + test "path must be unique" do + medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com" + assert medium.save! + + other_medium = Medium.new :name => "Ubuntu mirror", :path => "http://www.google.com" + assert !other_medium.save + end + + test "should not destroy while using" do + medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com" + assert medium.save! + + host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03", + :domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first, + :architecture => Architecture.first, :environment => Environment.first, :disk => "empty partition", + :ptable => Ptable.first + assert host.save! + + medium.hosts << host + + assert !medium.destroy + end +end -- 1.6.3.3