foreman_datacenter 1.22.1 → 1.24.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_datacenter/application_controller.rb +2 -0
  3. data/app/controllers/foreman_datacenter/racks_controller.rb +8 -1
  4. data/app/models/foreman_datacenter/rack.rb +36 -0
  5. data/app/views/foreman_datacenter/device_roles/show.html.erb +1 -2
  6. data/app/views/foreman_datacenter/device_types/show.html.erb +1 -2
  7. data/app/views/foreman_datacenter/manufacturers/show.html.erb +1 -2
  8. data/app/views/foreman_datacenter/platforms/show.html.erb +1 -2
  9. data/app/views/foreman_datacenter/rack_groups/show.html.erb +1 -2
  10. data/app/views/foreman_datacenter/racks/_device_position.html.erb +10 -1
  11. data/app/views/foreman_datacenter/racks/show.html.erb +1 -2
  12. data/app/views/foreman_datacenter/sites/show.html.erb +1 -2
  13. data/config/routes.rb +21 -1
  14. data/lib/foreman_datacenter/version.rb +1 -1
  15. data/test/controllers/foreman_datacenter/device_roles_controller_test.rb +133 -0
  16. data/test/controllers/foreman_datacenter/device_types_contoller_test.rb +108 -47
  17. data/test/controllers/foreman_datacenter/devices_controller_test.rb +132 -0
  18. data/test/controllers/foreman_datacenter/manufacturers_controller_test.rb +133 -0
  19. data/test/controllers/foreman_datacenter/platforms_contoller_test.rb +91 -48
  20. data/test/controllers/foreman_datacenter/rack_groups_contoller_test.rb +90 -43
  21. data/test/controllers/foreman_datacenter/racks_contoller_test.rb +111 -42
  22. data/test/controllers/foreman_datacenter/sites_contoller_test.rb +108 -81
  23. data/test/datacenter_helper.rb +8 -1
  24. data/test/factories/device.rb +5 -0
  25. data/test/factories/device_role.rb +6 -0
  26. data/test/factories/device_type.rb +30 -0
  27. data/test/factories/rack_group.rb +13 -14
  28. data/test/fixtures/foreman_datacenter/device_roles.yml +0 -1
  29. data/test/integration/foreman_datacenter/device_role_test.rb +35 -0
  30. data/test/integration/foreman_datacenter/device_type_test.rb +33 -0
  31. data/test/integration/foreman_datacenter/manufacturer_test.rb +33 -0
  32. data/test/integration/foreman_datacenter/platform_test.rb +35 -0
  33. data/test/integration/foreman_datacenter/rack_group_test.rb +35 -25
  34. data/test/integration/foreman_datacenter/rack_test.rb +37 -25
  35. data/test/integration/foreman_datacenter/site_test.rb +39 -29
  36. data/test/unit/foreman_datacenter_test.rb +1 -1
  37. metadata +56 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e96deecee872fb9556eaadaf8810780ff51756b52bd40899045ea80ffaeffbe8
4
- data.tar.gz: 868d381b9b0ee40a40104dbb68140ec6ad8ada53eb1affa10bd3d2b8f71079a1
3
+ metadata.gz: aa372e8673608cecc9343f4a2efa60d2d38dc77cb9ef37cfd55f8ec261907ccc
4
+ data.tar.gz: b806528ffcea447652114e76043f216d28eb50c2386f253ca93bd8808ab0ee35
5
5
  SHA512:
6
- metadata.gz: cd3c206a2840fd9c13b35c916e0d6575e29e907d57b76b9d5fb57931845be2293cc018fb2cb450ff8cbb487bd8dc8277d9157fadbf9dcd076608249dbf773886
7
- data.tar.gz: 18a82c60a9a04cfd7d51eda80bfcc2e065ad41cc3238294b95f90192e537a94e691365036517d9e5ced4b88d28872a56780d8e1961c0dda1adc2dbcbad67fb5f
6
+ metadata.gz: 8fa308e3840207c9a77aecfaa18491b578a73f5a1307bcea72fabafa1e97d4b3dfcf6bd9386803c847bbc410e75de3515d629c1e12227d4606d5e8385096c721
7
+ data.tar.gz: 3a00433a5afb85a305c687e66f153dd4279efe62f2ec842d6c67d321085062530dc261529436076b3ea0df0e74136bed184b79b388b98cf34f39eb6ecd0066b9
@@ -92,6 +92,8 @@ module ForemanDatacenter
92
92
  'move'
93
93
  when 'racks'
94
94
  'racks'
95
+ when 'export_to_csv'
96
+ 'export_to_csv'
95
97
  else
96
98
  super
97
99
  end
@@ -3,7 +3,7 @@ module ForemanDatacenter
3
3
  include Foreman::Controller::AutoCompleteSearch
4
4
  include ForemanDatacenter::Controller::Parameters::Rack
5
5
 
6
- before_action :find_resource, only: [:show, :edit, :update, :destroy, :devices, :move]
6
+ before_action :find_resource, only: [:show, :edit, :update, :destroy, :devices, :move, :export_to_csv]
7
7
 
8
8
  def index
9
9
  @racks = resource_base_search_and_page.includes(:site, :rack_group)
@@ -64,6 +64,13 @@ module ForemanDatacenter
64
64
  process_error object: @rack, error_msg: 'Current Rack haven\'t any Devices.' if @devices.empty?
65
65
  end
66
66
 
67
+ def export_to_csv
68
+ data = @rack.format_for_csv
69
+ file = File.open("#{@rack.name}.csv", "r")
70
+ send_file(file)
71
+ file.close
72
+ end
73
+
67
74
  def update_associated_objects
68
75
  begin
69
76
  @rack = ForemanDatacenter::Rack.find(request.env['HTTP_REFERER'].split('/')[-2])
@@ -52,8 +52,42 @@ module ForemanDatacenter
52
52
  count
53
53
  end
54
54
 
55
+ def format_for_csv
56
+ positioned_devices = self.positioned_devices
57
+ unpositioned_devices = self.unpositioned_devices
58
+ csv_string = CSV.generate do |csv|
59
+ csv << ["positions", "left", "full", "right", "no side"]
60
+ positioned_devices.each do |i|
61
+ pos = i[0].map{|p| "#{p}"+"U"}.join(",")
62
+ if i[1].size > 0
63
+ sort = sort_for_csv(i[1])
64
+ csv << [pos, sort[0], sort[1], sort[2], sort[3]]
65
+ else
66
+ csv << [pos]
67
+ end
68
+ end
69
+ unless unpositioned_devices.empty?
70
+ csv << []
71
+ csv << ["Unpositioned", unpositioned_devices.map(&:name).join(",")]
72
+ end
73
+
74
+ end
75
+ File.open("#{self.name}.csv", "w") {|f| f << csv_string}
76
+ end
77
+
55
78
  private
56
79
 
80
+ def sort_for_csv(device_array)
81
+ left, full, right, no_side = "", "", "", []
82
+ device_array.each do |d|
83
+ left = d.name if d.side == "left"
84
+ right = d.name if d.side == "right"
85
+ full = d.name if d.side == "full"
86
+ no_side << d.name if d.side == nil
87
+ end
88
+ [left, full, right, no_side.join(",")]
89
+ end
90
+
57
91
  def device_sorting(devices)
58
92
  devices.reverse.map { |d| [d[0].reverse, d[1]] }
59
93
  end
@@ -63,5 +97,7 @@ module ForemanDatacenter
63
97
  devices.each{|d| devs[1] << d[1][0]}
64
98
  return devs
65
99
  end
100
+
101
+
66
102
  end
67
103
  end
@@ -20,8 +20,7 @@
20
20
  objectid: @device_role.id,
21
21
  objectname: @device_role.to_label,
22
22
  associatedobjects: associated_objects('device_role') }
23
- )
24
- help_path %>
23
+ ) %>
25
24
 
26
25
  <div class="row">
27
26
  <div class="col-md-6">
@@ -20,8 +20,7 @@
20
20
  objectid: @device_type.id,
21
21
  objectname: @device_type.to_label,
22
22
  associatedobjects: associated_objects('device_type') }
23
- )
24
- help_path %>
23
+ ) %>
25
24
 
26
25
  <div class="row">
27
26
  <div class="col-md-6">
@@ -20,8 +20,7 @@
20
20
  objectid: @manufacturer.id,
21
21
  objectname: @manufacturer.to_label,
22
22
  associatedobjects: associated_objects('manufacturer') }
23
- )
24
- help_path %>
23
+ ) %>
25
24
 
26
25
  <div class="row">
27
26
  <div class="col-md-6">
@@ -20,8 +20,7 @@
20
20
  objectid: @platform.id,
21
21
  objectname: @platform.to_label,
22
22
  associatedobjects: associated_objects('platform') }
23
- )
24
- help_path %>
23
+ ) %>
25
24
 
26
25
  <div class="row">
27
26
  <div class="col-md-6">
@@ -25,8 +25,7 @@
25
25
  objectid: @rack_group.id,
26
26
  objectname: @rack_group.to_label,
27
27
  associatedobjects: associated_objects('rack_group') }
28
- )
29
- help_path %>
28
+ ) %>
30
29
 
31
30
  <div class="row">
32
31
 
@@ -1,5 +1,14 @@
1
1
  <div class="panel panel-default">
2
- <div class="panel-heading text-center"><h4 class="nonmargintop nonmarginbottom"><strong><%= link_to _("#{rack.name}"), rack_path(rack) %></strong></h4></div>
2
+ <div class="panel-heading text-center">
3
+ <h4 class="nonmargintop nonmarginbottom">
4
+ <strong>
5
+ <%= link_to _("#{rack.name}"), rack_path(rack) %>
6
+ </strong>
7
+ <strong>
8
+ <%= link_to 'Export to CSV', export_to_csv_rack_path(rack.id), class: "btn btn-primary btn-xs pull-right" %>
9
+ </strong>
10
+ </h4>
11
+ </div>
3
12
  <table class="<%= table_css_classes 'table-hover panel-body nonmarginbottom' %>">
4
13
  <tbody>
5
14
  <% rack.positioned_devices.each do |positions, devices| %>
@@ -26,8 +26,7 @@
26
26
  objectid: @rack.id,
27
27
  objectname: @rack.to_label,
28
28
  associatedobjects: associated_objects('rack') }
29
- )
30
- help_path %>
29
+ ) %>
31
30
 
32
31
  <div class="row">
33
32
  <div class="col-md-6">
@@ -25,8 +25,7 @@
25
25
  objectid: @site.id,
26
26
  objectname: @site.to_label,
27
27
  associatedobjects: associated_objects('site') }
28
- )
29
- help_path %>
28
+ ) %>
30
29
 
31
30
  <div class="row">
32
31
  <!-- Site -->
@@ -74,11 +74,30 @@ Foreman::Application.routes.draw do
74
74
  get 'datacenter/import_to_device', to: 'hosts#import_to_device',
75
75
  as: 'import_to_device'
76
76
 
77
- get '/api/:controller/(:action(/*welcome))'
77
+ # get '/api/:controller/(:action(/*welcome))'
78
78
  # get '/datacenter/(:controller)/help', :action => 'welcome', :as => "help"
79
79
 
80
80
  scope 'datacenter', module: :foreman_datacenter do
81
81
 
82
+ welcoming_controllers = [
83
+ 'console_ports',
84
+ 'device_interface_connections',
85
+ 'device_interface_connections',
86
+ 'device_roles',
87
+ 'device_types',
88
+ 'devices',
89
+ 'manufacturers',
90
+ 'platforms',
91
+ 'power_ports',
92
+ 'rack_groups',
93
+ 'racks',
94
+ 'sites',
95
+ ]
96
+
97
+ welcoming_controllers.each do |welcoming_controller|
98
+ get "#{welcoming_controller}/help", :action => :welcome, :controller => welcoming_controller
99
+ end
100
+
82
101
  post :site_update_associated_objects, to: "sites#update_associated_objects"
83
102
  post :rack_group_update_associated_objects, to: "rack_groups#update_associated_objects"
84
103
  post :rack_update_associated_objects, to: "racks#update_associated_objects"
@@ -94,6 +113,7 @@ Foreman::Application.routes.draw do
94
113
  end
95
114
  resources :racks do
96
115
  member do
116
+ get :export_to_csv
97
117
  get :move
98
118
  end
99
119
  collection do
@@ -1,3 +1,3 @@
1
1
  module ForemanDatacenter
2
- VERSION = '1.22.1'.freeze
2
+ VERSION = '1.24.2'.freeze
3
3
  end
@@ -0,0 +1,133 @@
1
+ require_relative '../../test_plugin_helper'
2
+
3
+ module ForemanDatacenter
4
+ class DeviceRolesControllerTest < ActionController::TestCase
5
+ describe ForemanDatacenter::DeviceRolesController do
6
+ setup do
7
+ @model = ForemanDatacenter::DeviceRole.first
8
+ end
9
+
10
+ basic_index_test 'device_roles'
11
+ basic_new_test
12
+ basic_edit_test 'device_role'
13
+ basic_pagination_per_page_test
14
+ basic_pagination_rendered_test
15
+
16
+ def test_create_invalid
17
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(false)
18
+ post :create, params: { :device_role => {:name => nil} }, session: set_session_user
19
+ assert_template 'new'
20
+ end
21
+
22
+ def test_create_valid(name = "test device_role")
23
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(true)
24
+ post :create, params: { :device_role => {:name => name, :color => 'Teal'} }, session: set_session_user
25
+ assert_redirected_to device_roles_url
26
+ end
27
+
28
+ def test_update_invalid
29
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(false)
30
+ put :update, params: { :id => @model.to_param, :device_role => {:name => "3243", :color => "Red"} }, session: set_session_user
31
+ assert_template 'edit'
32
+ end
33
+
34
+ def test_update_valid
35
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(true)
36
+ put :update, params: { :id => @model.to_param, :device_role => {:name => @model.name, :color => "Green"} }, session: set_session_user
37
+ assert_redirected_to device_roles_url
38
+ end
39
+
40
+ def test_destroy
41
+ test_create_valid "tobedeleted_test"
42
+ @new_dr = ForemanDatacenter::DeviceRole.find_by_name("tobedeleted_test")
43
+ delete :destroy, params: { :id => @new_dr.id }, session: set_session_user
44
+ assert_redirected_to device_roles_url
45
+ assert !ForemanDatacenter::DeviceRole.exists?(@new_dr.id)
46
+ end
47
+
48
+ test "should not get index when not permitted" do
49
+ setup_user
50
+ get :index, session: { :user => users(:one).id, :expires_at => 5.minutes.from_now }
51
+ assert_response :forbidden
52
+ assert_includes @response.body, 'view_device_roles'
53
+ end
54
+
55
+ test 'should not get show when not permitted' do
56
+ setup_user
57
+ get :show, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
58
+ assert_response :forbidden
59
+ assert_includes @response.body, 'view_device_roles'
60
+ end
61
+
62
+ test 'should not get edit when not permitted' do
63
+ setup_user
64
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
65
+ assert_response :forbidden
66
+ assert_includes @response.body, 'edit_device_roles'
67
+ end
68
+
69
+ test "should get index" do
70
+ setup_user("Viewer")
71
+ get :index, session: set_session_user
72
+ assert_response :success
73
+ assert_template 'index'
74
+ end
75
+
76
+ test 'should get show' do
77
+ setup_user("Viewer")
78
+ get :show, params: { :id => @model.id }, session: set_session_user
79
+ assert_response :success
80
+ assert_template 'show'
81
+ end
82
+
83
+ test 'should not get edit with viewer permissions' do
84
+ setup_user("Viewer")
85
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
86
+ assert_response :forbidden
87
+ assert_includes @response.body, 'edit_device_roles'
88
+ end
89
+
90
+ test 'should get edit' do
91
+ get :edit, params: { :id => @model.id }, session: set_session_user
92
+ assert_response :success
93
+ assert_template 'edit'
94
+ end
95
+
96
+ def setup_user(role = "")
97
+ @request.session[:user] = users(:one).id
98
+ users(:one).roles = [Role.default]
99
+ users(:one).roles << Role.find_by_name(role) if role != ""
100
+ # users(:one).roles = [Role.default, Role.find_by_name("Viewer")]
101
+ end
102
+
103
+ test "should_render_404_when_device_role_is_not_found" do
104
+ get :show, params: { id: 'no.such.device.role' }, session: set_session_user
105
+ assert_response :not_found
106
+ assert_template 'common/404'
107
+ end
108
+
109
+ test "should_not_destroy_device_role_when_not_permitted" do
110
+ setup_user
111
+ assert_difference('ForemanDatacenter::DeviceRole.count', 0) do
112
+ delete :destroy, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
113
+ end
114
+ assert_response :forbidden
115
+ end
116
+
117
+ test "should search by name" do
118
+ get :index, params: {:search => "name=\"device_role_1\""}, session: set_session_user
119
+ assert_response :success
120
+ refute_empty assigns(:device_roles)
121
+ assert assigns(:device_roles).include?(device_roles(:one))
122
+ end
123
+
124
+ test "should search by color" do
125
+ get :index, params: {:search => "color=\"Teal\""}, session: set_session_user
126
+ assert_response :success
127
+ refute_empty assigns(:device_roles)
128
+ assert assigns(:device_roles).include?(device_roles(:one))
129
+ end
130
+
131
+ end
132
+ end
133
+ end
@@ -13,78 +13,139 @@ module ForemanDatacenter
13
13
  basic_pagination_per_page_test
14
14
  basic_pagination_rendered_test
15
15
 
16
- def test_new_submit_button_id
17
- get :new, session: set_session_user
18
- assert_select "[data-id='aid_datacenter_device_types']"
19
- end
16
+ def test_create_invalid
17
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
18
+ post :create, params: { device_type: { model: nil } }, session: set_session_user
19
+ assert_template 'new'
20
+ end
20
21
 
21
- def test_new_cancel_button_id
22
- get :new, session: set_session_user
23
- assert_select "[data-id='aid_datacenter_device_types']"
24
- end
25
-
26
- def test_show_edit_button_id
27
- get :show, params: { :id => ForemanDatacenter::DeviceType.first.to_param }, session: set_session_user
28
- assert_select "[data-id='aid_device_types_#{ForemanDatacenter::DeviceType.first.id}_edit']"
22
+ def test_create_valid(model = "test device_type")
23
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
24
+ post :create, params: { device_type: { model: model, manufacturer_id: 1 } }, session: set_session_user
25
+ assert_redirected_to device_types_url
29
26
  end
30
27
 
31
- def test_show_delete_button_id
32
- get :show, params: { :id => ForemanDatacenter::DeviceType.first.to_param }, session: set_session_user
33
- assert_select "[data-id='aid_datacenter_device_types_#{ForemanDatacenter::DeviceType.first.id}']"
28
+ def test_update_invalid
29
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
30
+ put :update, params: { id: @model.to_param, device_type: { model: '3243', color: 'Red' } }, session: set_session_user
31
+ assert_template 'edit'
34
32
  end
35
33
 
36
- test "should_show_device_type" do
37
- setup_user
38
- get :show, params: { :id => ForemanDatacenter::DeviceType.first.to_param }, session: set_session_user
39
- assert_response :success
34
+ def test_update_valid
35
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
36
+ put :update, params: { id: @model.to_param, device_type: { model: @model.model, color: 'Green' } }, session: set_session_user
37
+ assert_redirected_to device_types_url
40
38
  end
41
39
 
42
40
  def test_create_invalid
43
41
  ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
44
- post :create, params: { :device_type => {:model => nil} }, session: set_session_user
42
+ post :create, params: { device_type: { model: nil } }, session: set_session_user
45
43
  assert_template 'new'
46
44
  end
47
45
 
48
- def test_create_valid
49
- ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
50
- post :create, params: { :device_type => {:model => 'test model'} }, session: set_session_user
51
- # assert_redirected_to device_types_url
52
- # assert_redirected_to device_type_url(ForemanDatacenter::DeviceType.first)
46
+ def test_destroy
47
+ test_create_valid "tobedeleted_test"
48
+ @new_dt = ForemanDatacenter::DeviceType.find_by_model("tobedeleted_test")
49
+ delete :destroy, params: { id: @new_dt.id }, session: set_session_user
50
+ assert_redirected_to device_types_url
51
+ assert !ForemanDatacenter::DeviceType.exists?(@new_dt.id)
53
52
  end
54
53
 
55
- def test_edit_submit_button_id
56
- get :edit, params: { :id => ForemanDatacenter::DeviceType.first }, session: set_session_user
57
- assert_select "[data-id='aid_update_foreman_datacenter_device_type']"
54
+ test "should not get index when not permitted" do
55
+ setup_user
56
+ get :index, session: { :user => users(:one).id, :expires_at => 5.minutes.from_now }
57
+ assert_response :forbidden
58
+ assert_includes @response.body, 'view_device_types'
58
59
  end
59
60
 
60
- def test_update_invalid
61
- ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
62
- put :update, params: { :id => ForemanDatacenter::DeviceType.first.to_param, :device_type => {:model => "3243"} }, session: set_session_user
63
- assert_template 'edit'
61
+ test 'should not get show when not permitted' do
62
+ setup_user
63
+ get :show, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
64
+ assert_response :forbidden
65
+ assert_includes @response.body, 'view_device_types'
64
66
  end
65
67
 
66
- def test_update_valid
67
- ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
68
- put :update, params: { :id => ForemanDatacenter::DeviceType.first.to_param, :device_type => {:model => ForemanDatacenter::DeviceType.first.model} }, session: set_session_user
69
- # assert_redirected_to device_type_url(ForemanDatacenter::DeviceType.first)
68
+ test 'should not get edit when not permitted' do
69
+ setup_user
70
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
71
+ assert_response :forbidden
72
+ assert_includes @response.body, 'edit_device_types'
70
73
  end
71
74
 
72
- def test_destroy
73
- device_type = ForemanDatacenter::DeviceType.first
74
- # architecture.hosts.delete_all
75
- # architecture.hostgroups.delete_all
76
- delete :destroy, params: { :id => device_type.id }, session: set_session_user
77
- assert_redirected_to device_types_url
78
- assert !ForemanDatacenter::DeviceType.exists?(device_type.id)
75
+ test "should get index" do
76
+ setup_user("Viewer")
77
+ get :index, session: set_session_user
78
+ assert_response :success
79
+ assert_template 'index'
80
+ end
81
+
82
+ test 'should get show' do
83
+ setup_user("Viewer")
84
+ get :show, params: { :id => @model.id }, session: set_session_user
85
+ assert_response :success
86
+ assert_template 'show'
87
+ end
88
+
89
+ test 'should not get edit with viewer permissions' do
90
+ setup_user("Viewer")
91
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
92
+ assert_response :forbidden
93
+ assert_includes @response.body, 'edit_device_types'
79
94
  end
80
95
 
81
- def setup_user
96
+ test 'should get edit' do
97
+ get :edit, params: { :id => @model.id }, session: set_session_user
98
+ assert_response :success
99
+ assert_template 'edit'
100
+ end
101
+
102
+ def setup_user(role = "")
82
103
  @request.session[:user] = users(:one).id
83
- users(:one).roles = [Role.default, Role.find_by_name('Viewer')]
104
+ users(:one).roles = [Role.default]
105
+ users(:one).roles << Role.find_by_name(role) if role != ""
106
+ # users(:one).roles = [Role.default, Role.find_by_name("Viewer")]
107
+ end
108
+
109
+ test "should_render_404_when_device_type_is_not_found" do
110
+ get :show, params: { id: 'no.such.device.type' }, session: set_session_user
111
+ assert_response :not_found
112
+ assert_template 'common/404'
84
113
  end
85
114
 
86
- def get_factory_name
87
- :device_type
115
+ test "should_not_destroy_device_type_when_not_permitted" do
116
+ setup_user
117
+ assert_difference('ForemanDatacenter::DeviceType.count', 0) do
118
+ delete :destroy, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
119
+ end
120
+ assert_response :forbidden
121
+ end
122
+
123
+ test "should search by model" do
124
+ get :index, params: {:search => "model=\"DeviceType_1NONE\""}, session: set_session_user
125
+ assert_response :success
126
+ refute_empty assigns(:device_types)
127
+ assert assigns(:device_types).include?(device_types(:one))
128
+ end
129
+
130
+ test "should search by manufacturer" do
131
+ get :index, params: {:search => "manufacturer=\"manufacturer_1\""}, session: set_session_user
132
+ assert_response :success
133
+ refute_empty assigns(:device_types)
134
+ assert assigns(:device_types).include?(device_types(:one))
135
+ end
136
+
137
+ test "should search by subdevice role" do
138
+ get :index, params: {:search => "subdevice_role=\"None\""}, session: set_session_user
139
+ assert_response :success
140
+ refute_empty assigns(:device_types)
141
+ assert assigns(:device_types).include?(device_types(:one))
142
+ end
143
+
144
+ test "should search by U height" do
145
+ get :index, params: {:search => "u_height=\"1\""}, session: set_session_user
146
+ assert_response :success
147
+ refute_empty assigns(:device_types)
148
+ assert assigns(:device_types).include?(device_types(:one))
88
149
  end
89
150
  end
90
151
  end