From 69837aa15782b0566997b15b91f356fe9dbd6996 Mon Sep 17 00:00:00 2001
From: Jochen Schalanda
+ <%= f.label :name %>
+ <%= f.label :path %>
+ <%= f.label :operatingsystems %> Currently used by <%= @medium.hosts.count %> hosts <%= f.submit "Submit" %>
+ <%= link_to "View All", media_path %>
+ <%= display_link_if_authorized "New Medium", hash_for_new_medium_path %> <%= link_to "Back to List", media_path %>
+ 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.
+
- <%= f.label :name %>
- <%= f.label :path %>
- <%= f.label :operatingsystems %> Currently used by <%= @media.hosts.count %> hosts <%= f.submit "Submit" %>
- <%= link_to "View All", medias_path %>
- <%= display_link_if_authorized "New Media", hash_for_new_media_path %> <%= link_to "Back to List", medias_path %>
- 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.
-
+ <%= f.text_field :name %>
+
+ <%= f.text_field :path, :size => 70 %>
+
+ 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.
+
+
+ <%= authorized_edit_habtm @medium, Operatingsystem %>
+
+ <% unless @medium.new_record? -%>
+
+
+<%= page_entries_info @media %>
+<%= will_paginate @media %>
+
+
+ <% for medium in @media %>
+ Name
+ Path
+ Operatingsystem
+
+ ">
+
+ <% end %>
+<%= 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 %>
+
+ Installation medium configuration
+
- <%= f.text_field :name %>
-
- <%= f.text_field :path, :size => 70 %>
-
- 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.
-
-
- <%= authorized_edit_habtm @media, Operatingsystem %>
-
- <% unless @media.new_record? -%>
-
-
-<%= page_entries_info @medias %>
-<%= will_paginate @medias %>
-
-
- <% for media in @medias %>
- Name
- Path
- Operatingsystem
-
- ">
-
- <% end %>
-<%= 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 %>
-
- Installation media configuration
-
- <% 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 @@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