From 69837aa15782b0566997b15b91f356fe9dbd6996 Mon Sep 17 00:00:00 2001 From: Jochen Schalanda Date: Thu, 18 Nov 2010 16:11:17 +0300 Subject: [PATCH] Fixes #263 - Refactored Foreman to use correct singular and pluralization of medium/media --- app/controllers/media_controller.rb | 57 +++++++++ app/controllers/medias_controller.rb | 57 --------- app/controllers/operatingsystems_controller.rb | 6 +- app/controllers/unattended_controller.rb | 4 +- app/helpers/medias_helper.rb | 2 - app/helpers/medium_helper.rb | 2 + app/models/debian.rb | 10 +- app/models/host.rb | 6 +- app/models/media.rb | 19 --- app/models/medium.rb | 19 +++ app/models/operatingsystem.rb | 18 ++-- app/models/redhat.rb | 14 +- app/views/home/_settings.html.erb | 2 +- app/views/hosts/_operatingsystem.html.erb | 2 +- app/views/media/_form.html.erb | 26 ++++ app/views/media/edit.html.erb | 7 + app/views/media/index.html.erb | 23 ++++ app/views/media/new.html.erb | 5 + app/views/media/welcome.html.erb | 23 ++++ app/views/medias/_form.html.erb | 26 ---- app/views/medias/edit.html.erb | 7 - app/views/medias/index.html.erb | 23 ---- app/views/medias/new.html.erb | 5 - app/views/medias/welcome.html.erb | 23 ---- app/views/operatingsystems/_form.html.erb | 4 +- app/views/operatingsystems/welcome.html.erb | 6 +- app/views/unattended/kickstart.rhtml | 2 +- config/routes.rb | 2 +- db/migrate/20090714132448_create_hosts.rb | 4 +- db/migrate/20090717025820_create_media.rb | 19 +++ db/migrate/20090717025820_create_medias.rb | 19 --- db/migrate/20090920043521_add_index_to_host.rb | 4 +- ...eate_media_operatingsystems_and_migrate_data.rb | 30 +++++ ...ate_medias_operatingsystems_and_migrate_data.rb | 30 ----- ...0100524080302_migrate_installation_media_uri.rb | 15 --- ...100524080302_migrate_installation_medium_uri.rb | 15 +++ db/migrate/20101118130026_correct_media.rb | 35 ++++++ lib/access_permissions.rb | 10 +- lib/foreman/default_data/loader.rb | 12 +- test/fixtures/hosts.yml | 6 +- test/fixtures/media.yml | 13 ++ test/fixtures/medias.yml | 13 -- test/fixtures/roles.yml | 12 +- test/functional/media_controller_test.rb | 66 +++++++++++ test/functional/medias_controller_test.rb | 66 ----------- test/functional/roles_controller_test.rb | 4 +- test/unit/helpers/media_helper_test.rb | 4 - test/unit/helpers/medium_helper_test.rb | 4 + test/unit/media_test.rb | 120 -------------------- test/unit/medium_test.rb | 120 ++++++++++++++++++++ 50 files changed, 528 insertions(+), 493 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 create mode 100644 app/views/media/welcome.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 delete mode 100644 app/views/medias/welcome.html.erb create mode 100644 db/migrate/20090717025820_create_media.rb delete mode 100644 db/migrate/20090717025820_create_medias.rb create mode 100644 db/migrate/20100523141204_create_media_operatingsystems_and_migrate_data.rb delete mode 100644 db/migrate/20100523141204_create_medias_operatingsystems_and_migrate_data.rb delete mode 100644 db/migrate/20100524080302_migrate_installation_media_uri.rb create mode 100644 db/migrate/20100524080302_migrate_installation_medium_uri.rb create mode 100644 db/migrate/20101118130026_correct_media.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..5b6345e --- /dev/null +++ b/app/controllers/media_controller.rb @@ -0,0 +1,57 @@ +class MediaController < ApplicationController + before_filter :find_medium, :only => %w{show edit update destroy} + + def index + respond_to do |format| + format.html do + @search = Medium.search params[:search] + @media = @search.paginate(:page => params[:page], :include => [:operatingsystems]) + end + format.json { render :json => Medium.all.as_json } + end + end + + def show + respond_to do |format| + format.json { render :json => @medium.as_json({:only => [:name, :id, :path]}) } + end + end + + def new + @medium = Medium.new + end + + def create + @medium = Medium.new(params[:medium]) + if @medium.save + notice "Successfully created medium." + redirect_to media_url + else + render :action => 'new' + end + end + + def edit + end + + def update + if @medium.update_attributes(params[:medium]) + notice "Successfully updated medium." + redirect_to media_url + else + render :action => 'edit' + end + end + + def destroy + @medium.destroy + notice "Successfully destroyed medium." + redirect_to media_url + end + + private + def find_medium + @medium = Medium.find(params[:id]) + end + +end diff --git a/app/controllers/medias_controller.rb b/app/controllers/medias_controller.rb deleted file mode 100644 index 98235eb..0000000 --- a/app/controllers/medias_controller.rb +++ /dev/null @@ -1,57 +0,0 @@ -class MediasController < ApplicationController - before_filter :find_media, :only => %w{show edit update destroy} - - def index - respond_to do |format| - format.html do - @search = Media.search params[:search] - @medias = @search.paginate(:page => params[:page], :include => [:operatingsystems]) - end - format.json { render :json => Media.all.as_json } - end - end - - def show - respond_to do |format| - format.json { render :json => @media.as_json({:only => [:name, :id, :path]}) } - end - end - - def new - @media = Media.new - end - - def create - @media = Media.new(params[:media]) - if @media.save - notice "Successfully created media." - redirect_to medias_url - else - render :action => 'new' - end - end - - def edit - end - - def update - if @media.update_attributes(params[:media]) - notice "Successfully updated media." - redirect_to medias_url - else - render :action => 'edit' - end - end - - def destroy - @media.destroy - notice "Successfully destroyed media." - redirect_to medias_url - end - - private - def find_media - @media = Media.find(params[:id]) - end - -end diff --git a/app/controllers/operatingsystems_controller.rb b/app/controllers/operatingsystems_controller.rb index 53f9065..064cc2c 100644 --- a/app/controllers/operatingsystems_controller.rb +++ b/app/controllers/operatingsystems_controller.rb @@ -7,7 +7,7 @@ class OperatingsystemsController < ApplicationController @search = Operatingsystem.search(params[:search]) @operatingsystems = @search.all.paginate(:page => params[:page], :include => [:architectures], :order => :name) end - format.json { render :json => Operatingsystem.all(:include => [:medias, :architectures, :ptables]) } + format.json { render :json => Operatingsystem.all(:include => [:media, :architectures, :ptables]) } end end @@ -55,10 +55,10 @@ class OperatingsystemsController < ApplicationController end def bootfiles - media = Media.find_by_name(params[:media]) + medium = Medium.find_by_name(params[:medium]) arch = Architecture.find_by_name(params[:architecture]) respond_to do |format| - format.json { render :json => @operatingsystem.pxe_files(media, arch)} + format.json { render :json => @operatingsystem.pxe_files(medium, arch)} end rescue => e respond_to do |format| diff --git a/app/controllers/unattended_controller.rb b/app/controllers/unattended_controller.rb index 21cdcf5..2be6fb4 100644 --- a/app/controllers/unattended_controller.rb +++ b/app/controllers/unattended_controller.rb @@ -25,7 +25,7 @@ class UnattendedController < ApplicationController @arch = @host.architecture.name os = @host.operatingsystem @osver = os.major.to_i - @mediapath = os.mediapath @host + @mediumpath = os.mediumpath @host @epel = os.epel @host @yumrepo = os.yumrepo @host @@ -105,7 +105,7 @@ class UnattendedController < ApplicationController # we try to match first based on the MAC, falling back to the IP conditions = (!maclist.empty? ? {:mac => maclist} : {:ip => ip}) - @host = Host.find(:first, :include => [:architecture, :media, :operatingsystem, :domain], :conditions => conditions) + @host = Host.find(:first, :include => [:architecture, :medium, :operatingsystem, :domain], :conditions => conditions) unless @host logger.info "#{controller_name}: unable to find ip/mac match for #{ip}" 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/debian.rb b/app/models/debian.rb index 3f0f069..b268f0f 100644 --- a/app/models/debian.rb +++ b/app/models/debian.rb @@ -3,11 +3,11 @@ class Debian < Operatingsystem PXEFILES = {:kernel => "linux", :initrd => "initrd.gz"} 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 # Override the class representation, as this breaks many rails helpers @@ -15,8 +15,8 @@ class Debian < Operatingsystem Operatingsystem end - def boot_files_uri(media, architecture) - raise "invalid media for #{to_s}" unless medias.include?(media) + def boot_files_uri(medium, architecture) + raise "invalid medium for #{to_s}" unless media.include?(medium) raise "invalid architecture for #{to_s}" unless architectures.include?(architecture) # Debian stores x86_64 arch is amd64 @@ -24,7 +24,7 @@ class Debian < Operatingsystem pxe_dir = "dists/#{release_name}/main/installer-#{arch}/current/images/netboot/#{guess_os}-installer/#{arch}" PXEFILES.values.collect do |img| - URI.parse("#{media_vars_to_uri(media.path, architecture.name, self)}/#{pxe_dir}/#{img}").normalize + URI.parse("#{medium_vars_to_uri(medium.path, architecture.name, self)}/#{pxe_dir}/#{img}").normalize end end diff --git a/app/models/host.rb b/app/models/host.rb index 5285367..6327c01 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -1,7 +1,7 @@ class Host < Puppet::Rails::Host include Authorization belongs_to :architecture - belongs_to :media + belongs_to :medium belongs_to :model belongs_to :domain belongs_to :operatingsystem @@ -109,7 +109,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 @@ -478,7 +478,7 @@ class Host < Puppet::Rails::Host # Returns a url pointing to boot file def url_for_boot file - "#{os.media_uri(self)}/#{os.url_for_boot(file)}" + "#{os.medium_uri(self)}/#{os.url_for_boot(file)}" end private diff --git a/app/models/media.rb b/app/models/media.rb deleted file mode 100644 index ec27953..0000000 --- a/app/models/media.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Media < ActiveRecord::Base - include Authorization - has_and_belongs_to_many :operatingsystems - has_many :hosts - validates_uniqueness_of :name - validates_uniqueness_of :path - 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 as_json(options={}) - super({:only => [:name, :id]}.merge(options)) - end - -end diff --git a/app/models/medium.rb b/app/models/medium.rb new file mode 100644 index 0000000..e1d3abf --- /dev/null +++ b/app/models/medium.rb @@ -0,0 +1,19 @@ +class Medium < ActiveRecord::Base + include Authorization + has_and_belongs_to_many :operatingsystems + has_many :hosts + validates_uniqueness_of :name + validates_uniqueness_of :path + 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 as_json(options={}) + super({:only => [:name, :id]}.merge(options)) + end + +end diff --git a/app/models/operatingsystem.rb b/app/models/operatingsystem.rb index b0288c6..519145d 100644 --- a/app/models/operatingsystem.rb +++ b/app/models/operatingsystem.rb @@ -4,7 +4,7 @@ require 'uri' class Operatingsystem < ActiveRecord::Base include Authorization has_many :hosts - has_and_belongs_to_many :medias + has_and_belongs_to_many :media has_and_belongs_to_many :ptables has_and_belongs_to_many :architectures has_and_belongs_to_many :puppetclasses @@ -42,12 +42,12 @@ class Operatingsystem < ActiveRecord::Base families.map{|e| OpenStruct.new(:name => e, :value => e) } end - def media_uri host, url = nil - url ||= host.media.path - media_vars_to_uri(url, host.architecture.name, host.os) + def medium_uri host, url = nil + url ||= host.medium.path + medium_vars_to_uri(url, host.architecture.name, host.os) end - def media_vars_to_uri (url, arch, os) + def medium_vars_to_uri (url, arch, os) URI.parse(url.gsub('$arch', arch). gsub('$major', os.major). gsub('$minor', os.minor). @@ -73,14 +73,14 @@ class Operatingsystem < ActiveRecord::Base "boot/#{to_s}-#{arch}".gsub(" ","-") end - def pxe_files(media, arch) - boot_files_uri(media, arch).collect do |img| + def pxe_files(medium, arch) + boot_files_uri(medium, arch).collect do |img| { pxe_prefix(arch).to_sym => img.to_s} end end def as_json(options={}) - {:operatingsystem => {:name => to_s, :id => id, :medias => medias, :architectures => architectures, :ptables => ptables}} + {:operatingsystem => {:name => to_s, :id => id, :media => media, :architectures => architectures, :ptables => ptables}} end private @@ -100,7 +100,7 @@ class Operatingsystem < ActiveRecord::Base self.release_name.downcase! unless defined?(Rake) or release_name.nil? or release_name.empty? end - def boot_files_uri(media = nil , architecture = nil) + def boot_files_uri(medium = nil , architecture = nil) "Abstract" end diff --git a/app/models/redhat.rb b/app/models/redhat.rb index 4706a3a..f2146f1 100644 --- a/app/models/redhat.rb +++ b/app/models/redhat.rb @@ -3,10 +3,10 @@ class Redhat < Operatingsystem PXEDIR = "images/pxeboot" PXEFILES = {:kernel => "vmlinuz", :initrd => "initrd.img"} - # 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' @@ -33,7 +33,7 @@ class Redhat < Operatingsystem 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 @@ -47,11 +47,11 @@ class Redhat < Operatingsystem Operatingsystem end - def boot_files_uri(media, architecture) - raise "invalid media for #{to_s}" unless medias.include?(media) + def boot_files_uri(medium, architecture) + raise "invalid medium for #{to_s}" unless media.include?(medium) raise "invalid architecture for #{to_s}" unless architectures.include?(architecture) PXEFILES.values.collect do |img| - URI.parse("#{media_vars_to_uri(media.path, architecture.name, self)}/#{PXEDIR}/#{img}").normalize + URI.parse("#{medium_vars_to_uri(medium.path, architecture.name, self)}/#{PXEDIR}/#{img}").normalize end end diff --git a/app/views/home/_settings.html.erb b/app/views/home/_settings.html.erb index daf391d..5fb6863 100644 --- a/app/views/home/_settings.html.erb +++ b/app/views/home/_settings.html.erb @@ -8,7 +8,7 @@ ['Global Parameters', common_parameters_url], ['Hardware Models', models_url], ['Host Groups', hostgroups_url], - ['Installation Medias', medias_url], + ['Installation Media', media_url], ['LDAP Authentication', auth_source_ldaps_url], ['Operating Systems', operatingsystems_url], ['Partition Tables', ptables_url], 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..0196ea4 --- /dev/null +++ b/app/views/media/_form.html.erb @@ -0,0 +1,26 @@ +<% form_for @medium do |f| %> + <%= f.error_messages %> +

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

+

+ <%= f.label :path %>
+ <%= f.text_field :path, :size => 70 %> +

+ + 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 :operatingsystems %>
+ <%= authorized_edit_habtm @medium, Operatingsystem %> +

+
+ <% 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..eb2aecd --- /dev/null +++ b/app/views/media/index.html.erb @@ -0,0 +1,23 @@ +<% title "Media" %> + + + + + + + + + <% for medium in @media %> + "> + + + + + + <% end %> +
NamePathOperatingsystem
<%= link_to_if_authorized h(medium), hash_for_edit_medium_path(:id => medium.id) %><%=h medium.path %><%=h medium.operatingsystems.to_sentence %> + <%= display_link_if_authorized "Destroy", hash_for_medium_path(:id => medium, :auth_action => :destroy), :confirm => "Delete #{medium.name}?", :method => :delete %> +
+<%= page_entries_info @media %> +<%= will_paginate @media %> +

<%= display_link_if_authorized "New Medium", hash_for_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/media/welcome.html.erb b/app/views/media/welcome.html.erb new file mode 100644 index 0000000..0e12f3a --- /dev/null +++ b/app/views/media/welcome.html.erb @@ -0,0 +1,23 @@ +
+

Installation medium configuration

+

+ As your configuration does not appear to have any installation media declared then you might want to configure some at this point. +

+

+ This information represents the source of one or more operating system's installation files, accessible via the network. + It will probably be a copy of one or more CD or DVDs, though it can be any valid URL, including the "nfs://" schema or even refer to the Distro's own release area. +

+

+ For example, if you have copied several Redhat release disks into a directory structure where the disk images are renamed 4.8 or 5.5, and each contained both x86_64 and i386 binaries, then you + could create a single medium entry describing them all. + The entry, which could be just named "Redhat" could contain a path like this "nfs://server/export/redhat/$version/$arch" or "http://server/redhat/$version/$arch". + + The keywords $version, $major and $minor will be interpolated back into the path specification to calculate the true URL address. +

+

+ You may also associate one or more operating systems with this medium or alternatively set this up later on the <%= link_to "Operating systems", operatingsystems_path -%> page. +

+

+ <%= link_to "New installation medium", new_medium_path -%>. +

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

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

-

- <%= f.label :path %>
- <%= f.text_field :path, :size => 70 %> -

- - 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 :operatingsystems %>
- <%= authorized_edit_habtm @media, Operatingsystem %> -

-
- <% 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 a3a93e4..0000000 --- a/app/views/medias/index.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<% title "Medias" %> - - - - - - - - - <% for media in @medias %> - "> - - - - - - <% end %> -
NamePathOperatingsystem
<%= link_to_if_authorized h(media), hash_for_edit_media_path(:id => media.id) %><%=h media.path %><%=h media.operatingsystems.to_sentence %> - <%= display_link_if_authorized "Destroy", hash_for_media_path(:id => media, :auth_action => :destroy), :confirm => "Delete #{media.name}?", :method => :delete %> -
-<%= page_entries_info @medias %> -<%= will_paginate @medias %> -

<%= display_link_if_authorized "New Media", hash_for_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/medias/welcome.html.erb b/app/views/medias/welcome.html.erb deleted file mode 100644 index 12e539d..0000000 --- a/app/views/medias/welcome.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -
-

Installation media configuration

-

- As your configuration does not appear to have any installation medias declared then you might want to configure some at this point. -

-

- This information represents the source of one or more operating system's installation files, accessible via the network. - It will probably be a copy of one or more CD or DVDs, though it can be any valid URL, including the "nfs://" schema or even refer to the Distro's own release area. -

-

- For example, if you have copied several Redhat release disks into a directory structure where the disk images are renamed 4.8 or 5.5, and each contained both x86_64 and i386 binaries, then you - could create a single media entry describing them all. - The entry, which could be just named "Redhat" could contain a path like this "nfs://server/export/redhat/$version/$arch" or "http://server/redhat/$version/$arch". - - The keywords $version, $major and $minor will be interpolated back into the path specification to calculate the true URL address. -

-

- You may also associate one or more operating systems with this media or alternatively set this up later on the <%= link_to "Operating systems", operatingsystems_path -%> page. -

-

- <%= link_to "New installation media", new_media_path -%>. -

-
diff --git a/app/views/operatingsystems/_form.html.erb b/app/views/operatingsystems/_form.html.erb index 69804e2..ed0406a 100644 --- a/app/views/operatingsystems/_form.html.erb +++ b/app/views/operatingsystems/_form.html.erb @@ -29,8 +29,8 @@ <% end -%>

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

diff --git a/app/views/operatingsystems/welcome.html.erb b/app/views/operatingsystems/welcome.html.erb index 8be19d4..d4465b0 100644 --- a/app/views/operatingsystems/welcome.html.erb +++ b/app/views/operatingsystems/welcome.html.erb @@ -2,18 +2,18 @@

Operatingsystem configuration

As your installation does not appear to have any operating systems declared then you might want to configure some at this point. (If you have not already visited the <%= link_to "partition table", ptables_path -%> or - <%= link_to "installation media", medias_path -%> pages then it would be sensible to initialise these first.) + <%= link_to "installation medium", media_path -%> pages then it would be sensible to initialise these first.)

For example, if you intend to support "lucid" Ubuntu then enter "Ubuntu", "10", "04", "lucid" and select the "Debian" family of operatingsystems. The Family selection allows Foreman to properly understand the - layout of the operatingsystem's installation media. + layout of the operatingsystem's installation medium.

This page also provides a mechanism for selecting the target architectures that your installation will be building. You will also be prompted to provide a default disk layout for all machines of this type and from where you would be expecting the machine to retrieve its installation files.

- It is possible that some of these selections are empty, and if so, you should go to the correct settings page to setup your <%= link_to "installation medias", medias_path -%> and <%= link_to "disk layouts", ptables_path -%>. + It is possible that some of these selections are empty, and if so, you should go to the correct settings page to setup your <%= link_to "installation media", media_path -%> and <%= link_to "disk layouts", ptables_path -%>.

<%= link_to "New operatingsystem", new_operatingsystem_path -%>. diff --git a/app/views/unattended/kickstart.rhtml b/app/views/unattended/kickstart.rhtml index 2318a56..e83fa92 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 84818eb..5eb086e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,7 +26,7 @@ ActionController::Routing::Routes.draw do |map| map.connect "/lookup", :controller => "lookup_keys", :action => "q" map.resources :domains, :requirements => {:id => /[^\/]+/} map.resources :operatingsystems, :member => {:bootfiles => :get} - 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/20090714132448_create_hosts.rb b/db/migrate/20090714132448_create_hosts.rb index 20c2fb8..654374d 100644 --- a/db/migrate/20090714132448_create_hosts.rb +++ b/db/migrate/20090714132448_create_hosts.rb @@ -25,7 +25,7 @@ class CreateHosts < ActiveRecord::Migration add_column :hosts, :subnet_id, :integer add_column :hosts, :sp_subnet_id, :integer add_column :hosts, :ptable_id, :integer - add_column :hosts, :media_id, :integer + add_column :hosts, :medium_id, :integer add_column :hosts, :build, :boolean, :default => true add_column :hosts, :comment, :text add_column :hosts, :disk, :text @@ -39,7 +39,7 @@ class CreateHosts < ActiveRecord::Migration remove_columns :hosts, :mac, :sp_mac, :sp_ip, :sp_name, :root_pass, :serial, :puppetmaster, :puppet_status, :domain_id, :architecture_id, :operatingsystem_id, :environment_id, :subnet_id, :sp_subnet_id, :ptable_id, :hosttype_id, - :media_id, :build, :comment, :disk, :installed_at + :medium_id, :build, :comment, :disk, :installed_at else drop_table :hosts end diff --git a/db/migrate/20090717025820_create_media.rb b/db/migrate/20090717025820_create_media.rb new file mode 100644 index 0000000..abde6cb --- /dev/null +++ b/db/migrate/20090717025820_create_media.rb @@ -0,0 +1,19 @@ +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 mirror", :path => "http://mirror.averse.net/centos/$major.$minor/os/$arch" + Medium.create :name => "Fedora Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/$major/Fedora/$arch/os/" + Medium.create :name => "RedHat Beta", :path => "http://ftp.redhat.com/pub/redhat/rhel/beta/$major/$arch/os" + Medium.create :name => "Ubuntu Mirror", :path => "http://sg.archive.ubuntu.com" + + end + + def self.down + drop_table :media + end +end diff --git a/db/migrate/20090717025820_create_medias.rb b/db/migrate/20090717025820_create_medias.rb deleted file mode 100644 index 29b94ee..0000000 --- a/db/migrate/20090717025820_create_medias.rb +++ /dev/null @@ -1,19 +0,0 @@ -class CreateMedias < ActiveRecord::Migration - def self.up - 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 mirror", :path => "http://mirror.averse.net/centos/$major.$minor/os/$arch" - Media.create :name => "Fedora Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/$major/Fedora/$arch/os/" - Media.create :name => "RedHat Beta", :path => "http://ftp.redhat.com/pub/redhat/rhel/beta/$major/$arch/os" - Media.create :name => "Ubuntu Mirror", :path => "http://sg.archive.ubuntu.com" - - end - - def self.down - drop_table :medias - end -end diff --git a/db/migrate/20090920043521_add_index_to_host.rb b/db/migrate/20090920043521_add_index_to_host.rb index 7570682..d8f4c5f 100644 --- a/db/migrate/20090920043521_add_index_to_host.rb +++ b/db/migrate/20090920043521_add_index_to_host.rb @@ -7,7 +7,7 @@ class AddIndexToHost < ActiveRecord::Migration add_index "hosts", :architecture_id, :name => 'host_arch_id_ix' add_index "hosts", :operatingsystem_id, :name => 'host_os_id_ix' add_index "hosts", :environment_id, :name => 'host_env_id_ix' - add_index "hosts", :media_id, :name => 'host_media_id_ix' + add_index "hosts", :medium_id, :name => 'host_medium_id_ix' add_index "hosts", :hostgroup_id, :name => 'host_group_id_ix' end @@ -19,7 +19,7 @@ class AddIndexToHost < ActiveRecord::Migration remove_index "hosts", :name => 'host_arch_id_ix' remove_index "hosts", :name => 'host_os_id_ix' remove_index "hosts", :name => 'host_env_id_ix' - remove_index "hosts", :name => 'host_media_id_ix' + remove_index "hosts", :name => 'host_medium_id_ix' remove_index "hosts", :name => 'host_group_id_ix' end end diff --git a/db/migrate/20100523141204_create_media_operatingsystems_and_migrate_data.rb b/db/migrate/20100523141204_create_media_operatingsystems_and_migrate_data.rb new file mode 100644 index 0000000..e4abc91 --- /dev/null +++ b/db/migrate/20100523141204_create_media_operatingsystems_and_migrate_data.rb @@ -0,0 +1,30 @@ +class CreateMediaOperatingsystemsAndMigrateData < ActiveRecord::Migration + def self.up + + medium_hash = Hash.new + Medium.all.each do |medium| + unless medium.operatingsystem_id.nil? + if Operatingsystem.exists?(medium.operatingsystem_id) + os = Operatingsystem.find(medium.operatingsystem_id) + medium_hash[os] = medium + else + say "skipped #{medium}" + end + end + end + + create_table :media_operatingsystems , :id => false do |t| + t.references :medium, :null => false + t.references :operatingsystem, :null => false + end + + medium_hash.keys.each { |os| os.media << medium_hash[os] } + + remove_column :media, :operatingsystem_id + end + + def self.down + add_column :media, :operatingsystem_id, :integer + drop_table :media_operatingsystems + end +end diff --git a/db/migrate/20100523141204_create_medias_operatingsystems_and_migrate_data.rb b/db/migrate/20100523141204_create_medias_operatingsystems_and_migrate_data.rb deleted file mode 100644 index 6974b73..0000000 --- a/db/migrate/20100523141204_create_medias_operatingsystems_and_migrate_data.rb +++ /dev/null @@ -1,30 +0,0 @@ -class CreateMediasOperatingsystemsAndMigrateData < ActiveRecord::Migration - def self.up - - media_hash = Hash.new - Media.all.each do |medium| - unless medium.operatingsystem_id.nil? - if Operatingsystem.exists?(medium.operatingsystem_id) - os = Operatingsystem.find(medium.operatingsystem_id) - media_hash[os] = medium - else - say "skipped #{medium}" - end - end - end - - create_table :medias_operatingsystems , :id => false do |t| - t.references :media, :null => false - t.references :operatingsystem, :null => false - end - - media_hash.keys.each { |os| os.medias << media_hash[os] } - - remove_column :medias, :operatingsystem_id - end - - def self.down - add_column :medias, :operatingsystem_id, :integer - drop_table :medias_operatingsystems - end -end diff --git a/db/migrate/20100524080302_migrate_installation_media_uri.rb b/db/migrate/20100524080302_migrate_installation_media_uri.rb deleted file mode 100644 index bcab5cd..0000000 --- a/db/migrate/20100524080302_migrate_installation_media_uri.rb +++ /dev/null @@ -1,15 +0,0 @@ -class MigrateInstallationMediaUri < ActiveRecord::Migration - def self.up - Media.all.each { |medium| - matches = /^([^:]+):(\/.+)/.match(medium.path) - - if matches.size == 3 and ![ 'http', 'https', 'ftp', 'ftps', 'nfs' ].include?(matches[1]) - medium.path = 'nfs://' + matches[1] + matches[2] - medium.save - end - } - end - - def self.down - end -end diff --git a/db/migrate/20100524080302_migrate_installation_medium_uri.rb b/db/migrate/20100524080302_migrate_installation_medium_uri.rb new file mode 100644 index 0000000..e9cf85b --- /dev/null +++ b/db/migrate/20100524080302_migrate_installation_medium_uri.rb @@ -0,0 +1,15 @@ +class MigrateInstallationMediumUri < ActiveRecord::Migration + def self.up + Medium.all.each { |medium| + matches = /^([^:]+):(\/.+)/.match(medium.path) + + if matches.size == 3 and ![ 'http', 'https', 'ftp', 'ftps', 'nfs' ].include?(matches[1]) + medium.path = 'nfs://' + matches[1] + matches[2] + medium.save + end + } + end + + def self.down + end +end diff --git a/db/migrate/20101118130026_correct_media.rb b/db/migrate/20101118130026_correct_media.rb new file mode 100644 index 0000000..dd58055 --- /dev/null +++ b/db/migrate/20101118130026_correct_media.rb @@ -0,0 +1,35 @@ +class CorrectMedia < ActiveRecord::Migration + def self.up + if table_exists? :medias + if table_exists? :medias_operatingsystems + rename_column :medias_operatingsystems, :media_id, :medium_id + rename_table :medias_operatingsystems, :media_operatingsystems + end + + change_table :hosts do |t| + t.remove_index :name => :host_media_id_ix + t.rename :media_id, :medium_id + t.index :medium_id, :name => :host_medium_id_ix + end + + rename_table :medias, :media + end + end + + def self.down + if table_exists? :media + if table_exists? :media_operatingsystems + rename_column :medias_operatingsystems, :medium_id, :media_id + rename_table :media_operatingsystems, :medias_operatingsystems + end + + change_table :hosts do |t| + t.remove_index :name => :host_medium_id_ix + t.rename :medium_id, :media_id + t.index :media_id, :name => :host_media_id_ix + end + + rename_table :media, :medias + end + end +end diff --git a/lib/access_permissions.rb b/lib/access_permissions.rb index 158dc92..b2fbf71 100644 --- a/lib/access_permissions.rb +++ b/lib/access_permissions.rb @@ -62,11 +62,11 @@ Foreman::AccessControl.map do |map| map.permission :destroy_hosts, {:hosts => [:destroy, :multiple_actions, :reset_multiple, :multiple_destroy, :submit_multiple_destroy]} end - map.security_block :medias do |map| - map.permission :view_medias, {:medias => [:index, :show]} - map.permission :create_medias, {:medias => [:new, :create]} - map.permission :edit_medias, {:medias => [:edit, :update]} - map.permission :destroy_medias, {:medias => [:destroy]} + map.security_block :media do |map| + map.permission :view_media, {:media => [:index, :show]} + map.permission :create_media, {:media => [:new, :create]} + map.permission :edit_media, {:media => [:edit, :update]} + map.permission :destroy_media, {:media => [:destroy]} end map.security_block :models do |map| diff --git a/lib/foreman/default_data/loader.rb b/lib/foreman/default_data/loader.rb index ae7ec7b..dc2546c 100644 --- a/lib/foreman/default_data/loader.rb +++ b/lib/foreman/default_data/loader.rb @@ -62,7 +62,7 @@ module Foreman :view_hostgroups, :view_domains, :view_operatingsystems, - :view_medias, + :view_media, :view_models, :view_environments, :view_architectures, @@ -101,10 +101,10 @@ module Foreman :create_hosts, :edit_hosts, :destroy_hosts, - :view_medias, - :create_medias, - :edit_medias, - :destroy_medias, + :view_media, + :create_media, + :edit_media, + :destroy_media, :view_models, :view_operatingsystems, :view_ptables, @@ -127,7 +127,7 @@ module Foreman :view_hostgroups, :view_domains, :view_operatingsystems, - :view_medias, + :view_media, :view_models, :view_environments, :view_architectures, diff --git a/test/fixtures/hosts.yml b/test/fixtures/hosts.yml index d61b35c..cd35d2e 100644 --- a/test/fixtures/hosts.yml +++ b/test/fixtures/hosts.yml @@ -19,7 +19,7 @@ two: operatingsystem: one ptable: one domain: yourdomain - media: one + medium: one otherfullhost: name: otherfullhost @@ -58,7 +58,7 @@ redhat: build: true ptable: one domain: yourdomain - media: one + medium: one operatingsystem: redhat ubuntu: @@ -71,4 +71,4 @@ ubuntu: build: true ptable: ubuntu domain: yourdomain - media: ubuntu + medium: ubuntu diff --git a/test/fixtures/media.yml b/test/fixtures/media.yml new file mode 100644 index 0000000..e88d848 --- /dev/null +++ b/test/fixtures/media.yml @@ -0,0 +1,13 @@ +# 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 + +ubuntu: + name: Ubuntu Mirror + path: http://sg.archive.ubuntu.com + +unused: + name: unused + path: http://nothing.intersting.com diff --git a/test/fixtures/medias.yml b/test/fixtures/medias.yml deleted file mode 100644 index e88d848..0000000 --- a/test/fixtures/medias.yml +++ /dev/null @@ -1,13 +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 - -ubuntu: - name: Ubuntu Mirror - path: http://sg.archive.ubuntu.com - -unused: - name: unused - path: http://nothing.intersting.com diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index 6e88041..759a943 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -38,10 +38,10 @@ manager: - :create_hosts - :edit_hosts - :destroy_hosts - - :view_medias - - :create_medias - - :edit_medias - - :destroy_medias + - :view_media + - :create_media + - :edit_media + - :destroy_media - :view_models - :create_models - :edit_models @@ -119,7 +119,7 @@ viewer: - :view_globals - :view_hostgroups - :view_hosts - - :view_medias + - :view_media - :view_models - :view_operatingsystems - :view_ptables @@ -141,7 +141,7 @@ default_user: - :view_hostgroups - :view_domains - :view_oses - - :view_medias + - :view_media - :view_models - :view_environments - :view_architectures diff --git a/test/functional/media_controller_test.rb b/test/functional/media_controller_test.rb new file mode 100644 index 0000000..611beba --- /dev/null +++ b/test/functional/media_controller_test.rb @@ -0,0 +1,66 @@ +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 = media(:unused) + delete :destroy, {:id => medium}, set_session_user + assert_redirected_to media_url + assert !Medium.exists?(medium.id) + end + + def setup_user + @request.session[:user] = users(:one).id + users(:one).roles = [Role.find_by_name('Anonymous'), Role.find_by_name('Viewer')] + end + + test 'user with viewer rights should fail to edit a medium' do + setup_user + get :edit, {:id => Medium.first.id} + assert @response.status == '403 Forbidden' + end + + test 'user with viewer rights should succeed in viewing media' do + setup_user + get :index + assert_response :success + end +end diff --git a/test/functional/medias_controller_test.rb b/test/functional/medias_controller_test.rb deleted file mode 100644 index 75f796d..0000000 --- a/test/functional/medias_controller_test.rb +++ /dev/null @@ -1,66 +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 = medias(:unused) - delete :destroy, {:id => media}, set_session_user - assert_redirected_to medias_url - assert !Media.exists?(media.id) - end - - def setup_user - @request.session[:user] = users(:one).id - users(:one).roles = [Role.find_by_name('Anonymous'), Role.find_by_name('Viewer')] - end - - test 'user with viewer rights should fail to edit a media' do - setup_user - get :edit, {:id => Media.first.id} - assert @response.status == '403 Forbidden' - end - - test 'user with viewer rights should succeed in viewing medias' do - setup_user - get :index - assert_response :success - end -end diff --git a/test/functional/roles_controller_test.rb b/test/functional/roles_controller_test.rb index 86866d0..3287b56 100644 --- a/test/functional/roles_controller_test.rb +++ b/test/functional/roles_controller_test.rb @@ -120,6 +120,6 @@ class RolesControllerTest < ActionController::TestCase assert Role.find(1).permissions.empty? end - viewable = %w{Architecture Audit AuthSourceLdap Dashboard Domain Environment LookupKey FactValue CommonParameter Hostgroup Host Media Model Operatingsystem Ptable Puppetclass Report Setting Statistic Usergroup User} - editable = %w{Architecture Audit AuthSourceLdap Domain Environment LookupKey CommonParameter Hostgroup Host Media Model Operatingsystem Ptable Puppetclass Report Usergroup User} + viewable = %w{Architecture Audit AuthSourceLdap Dashboard Domain Environment LookupKey FactValue CommonParameter Hostgroup Host Medium Model Operatingsystem Ptable Puppetclass Report Setting Statistic Usergroup User} + editable = %w{Architecture Audit AuthSourceLdap Domain Environment LookupKey CommonParameter Hostgroup Host Medium Model Operatingsystem Ptable Puppetclass Report Usergroup User} 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 bc2f38c..0000000 --- a/test/unit/media_test.rb +++ /dev/null @@ -1,120 +0,0 @@ -require 'test_helper' - -class MediaTest < ActiveSupport::TestCase - setup do - User.current = User.find_by_login "admin" - end - - 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 - - def setup_user operation - @one = users(:one) - as_admin do - role = Role.find_or_create_by_name :name => "#{operation}_medias" - role.permissions = ["#{operation}_medias".to_sym] - @one.roles = [role] - @one.save! - end - User.current = @one - end - - test "user with create permissions should be able to create" do - setup_user "create" - record = Media.create :name => "dummy", :path => "http://hello" - assert record.valid? - assert !record.new_record? - end - - test "user with view permissions should not be able to create" do - setup_user "view" - record = Media.create :name => "dummy", :path => "http://hello" - assert record.valid? - assert record.new_record? - end - - test "user with destroy permissions should be able to destroy" do - setup_user "destroy" - record = Media.first - as_admin do - record.hosts = [] - end - assert record.destroy - assert record.frozen? - end - - test "user with edit permissions should not be able to destroy" do - setup_user "edit" - record = Media.first - assert !record.destroy - assert !record.frozen? - end - - test "user with edit permissions should be able to edit" do - setup_user "edit" - record = Media.first - record.name = "renamed" - assert record.save - end - - test "user with destroy permissions should not be able to edit" do - setup_user "destroy" - record = Media.first - record.name = "renamed" - as_admin do - record.hosts = [] - end - assert !record.save - assert record.valid? - end - -end diff --git a/test/unit/medium_test.rb b/test/unit/medium_test.rb new file mode 100644 index 0000000..973021d --- /dev/null +++ b/test/unit/medium_test.rb @@ -0,0 +1,120 @@ +require 'test_helper' + +class MediumTest < ActiveSupport::TestCase + setup do + User.current = User.find_by_login "admin" + end + + 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 + + def setup_user operation + @one = users(:one) + as_admin do + role = Role.find_or_create_by_name :name => "#{operation}_media" + role.permissions = ["#{operation}_media".to_sym] + @one.roles = [role] + @one.save! + end + User.current = @one + end + + test "user with create permissions should be able to create" do + setup_user "create" + record = Medium.create :name => "dummy", :path => "http://hello" + assert record.valid? + assert !record.new_record? + end + + test "user with view permissions should not be able to create" do + setup_user "view" + record = Medium.create :name => "dummy", :path => "http://hello" + assert record.valid? + assert record.new_record? + end + + test "user with destroy permissions should be able to destroy" do + setup_user "destroy" + record = Medium.first + as_admin do + record.hosts = [] + end + assert record.destroy + assert record.frozen? + end + + test "user with edit permissions should not be able to destroy" do + setup_user "edit" + record = Medium.first + assert !record.destroy + assert !record.frozen? + end + + test "user with edit permissions should be able to edit" do + setup_user "edit" + record = Medium.first + record.name = "renamed" + assert record.save + end + + test "user with destroy permissions should not be able to edit" do + setup_user "destroy" + record = Medium.first + record.name = "renamed" + as_admin do + record.hosts = [] + end + assert !record.save + assert record.valid? + end + +end -- 1.7.3.2