rocketjob_mission_control 4.3.0 → 5.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +12 -12
  3. data/app/controllers/rocket_job_mission_control/application_controller.rb +1 -2
  4. data/app/controllers/rocket_job_mission_control/dirmon_entries_controller.rb +20 -19
  5. data/app/controllers/rocket_job_mission_control/jobs_controller.rb +36 -35
  6. data/app/controllers/rocket_job_mission_control/servers_controller.rb +32 -38
  7. data/app/datatables/rocket_job_mission_control/abstract_datatable.rb +8 -6
  8. data/app/datatables/rocket_job_mission_control/active_workers_datatable.rb +5 -5
  9. data/app/datatables/rocket_job_mission_control/dirmon_entries_datatable.rb +4 -4
  10. data/app/datatables/rocket_job_mission_control/jobs_datatable.rb +55 -62
  11. data/app/datatables/rocket_job_mission_control/servers_datatable.rb +13 -14
  12. data/app/helpers/rocket_job_mission_control/application_helper.rb +42 -41
  13. data/app/helpers/rocket_job_mission_control/jobs_helper.rb +9 -10
  14. data/app/helpers/rocket_job_mission_control/pagination_helper.rb +1 -1
  15. data/app/helpers/rocket_job_mission_control/servers_helper.rb +6 -6
  16. data/app/helpers/rocket_job_mission_control/slices_helper.rb +2 -4
  17. data/app/models/rocket_job_mission_control/access_policy.rb +1 -2
  18. data/app/models/rocket_job_mission_control/authorization.rb +3 -2
  19. data/app/models/rocket_job_mission_control/job_sanitizer.rb +14 -17
  20. data/app/models/rocket_job_mission_control/query.rb +2 -5
  21. data/app/views/rocket_job_mission_control/jobs/_exceptions.html.erb +1 -1
  22. data/app/views/rocket_job_mission_control/jobs/edit_slice.html.erb +1 -1
  23. data/app/views/rocket_job_mission_control/servers/index.html.erb +2 -2
  24. data/config/initializers/assets.rb +5 -7
  25. data/config/locales/en.yml +3 -0
  26. data/config/routes.rb +20 -21
  27. data/lib/rocket_job_mission_control/engine.rb +8 -9
  28. data/lib/rocket_job_mission_control/version.rb +1 -1
  29. data/lib/rocketjob_mission_control.rb +1 -1
  30. data/test/compare_hashes.rb +1 -2
  31. data/test/controllers/rocket_job_mission_control/application_controller_test.rb +13 -13
  32. data/test/controllers/rocket_job_mission_control/dirmon_entries_controller_test.rb +107 -108
  33. data/test/controllers/rocket_job_mission_control/jobs_controller_test.rb +89 -93
  34. data/test/controllers/rocket_job_mission_control/servers_controller_test.rb +66 -103
  35. data/test/helpers/rocket_job_mission_control/application_helper_test.rb +13 -14
  36. data/test/helpers/rocket_job_mission_control/jobs_helper_test.rb +31 -31
  37. data/test/helpers/rocket_job_mission_control/pagination_helper_test.rb +7 -9
  38. data/test/helpers/rocket_job_mission_control/servers_helper_test.rb +15 -15
  39. data/test/helpers/rocket_job_mission_control/slices_helper_test.rb +8 -10
  40. data/test/models/rocket_job_mission_control/job_sanitizer_test.rb +39 -40
  41. data/test/models/rocket_job_mission_control/query_test.rb +26 -28
  42. data/test/test_helper.rb +12 -12
  43. metadata +28 -28
@@ -1,10 +1,9 @@
1
- require_relative '../../test_helper'
2
- require_relative '../../compare_hashes'
1
+ require_relative "../../test_helper"
2
+ require_relative "../../compare_hashes"
3
3
 
4
4
  module RocketJobMissionControl
5
5
  class ServersControllerTest < ActionController::TestCase
6
6
  describe ServersController do
7
-
8
7
  before do
9
8
  set_role(:admin)
10
9
  RocketJob::Job.delete_all
@@ -27,137 +26,106 @@ module RocketJobMissionControl
27
26
  end
28
27
  end
29
28
 
30
- [:stop, :pause, :resume].each do |server_action|
29
+ %i[stop pause resume].each do |server_action|
31
30
  describe "PATCH ##{server_action}" do
32
- describe 'with a valid server id' do
31
+ describe "with a valid server id" do
33
32
  before do
34
33
  server.pause! if server_action == :resume
35
- params = {id: server.id}
36
- params = {params: params} if Rails.version.to_i >= 5
37
- patch server_action, params
38
34
  end
39
35
 
40
- it 'redirects to servers' do
36
+ it "redirects to servers" do
37
+ patch server_action, params: {id: server.id}
41
38
  assert_redirected_to servers_path
42
39
  end
43
40
 
44
41
  it "#{server_action} the server" do
45
- results = {stop: :stopping?, pause: :paused?, resume: :running?}
46
- assert server.reload.send(results[server_action])
47
- end
48
- end
49
-
50
- describe "when the server fails to #{server_action}" do
51
- before do
52
- server.pause! if server_action == :pause
53
- server.stop! if server_action == :stop
54
- params = {id: server.id}
55
- params = {params: params} if Rails.version.to_i >= 5
56
- patch server_action, params
57
- end
58
-
59
- it 'redirects to servers' do
60
- assert_redirected_to servers_path
61
- end
62
-
63
- it 'displays a flash message' do
64
- assert_equal I18n.t(:failure, scope: [:server, server_action]), flash[:alert]
42
+ action = server_id = nil
43
+ RocketJob::Subscribers::Server.stub(:publish, lambda { |_action, args|
44
+ action = _action
45
+ server_id = args[:server_id]
46
+ }) do
47
+ patch server_action, params: {id: server.id}
48
+ end
49
+ assert_equal server_action, action
50
+ assert_equal server.id, server_id
65
51
  end
66
52
  end
67
53
  end
68
54
  end
69
55
 
70
- describe 'PATCH #update_all' do
71
- RocketJobMissionControl::ServersController::VALID_ACTIONS.each do |server_action, action_message|
56
+ describe "PATCH #update_all" do
57
+ RocketJobMissionControl::ServersController::VALID_ACTIONS.each do |server_action, _action_message|
72
58
  describe "with '#{server_action}' as the server_action param" do
73
59
  before do
74
- params = {server_action: server_action}
75
- params = {params: params} if Rails.version.to_i >= 5
76
- patch :update_all, params
60
+ patch :update_all, params: {server_action: server_action}
77
61
  end
78
62
 
79
- it 'redirects to servers' do
63
+ it "redirects to servers" do
80
64
  assert_redirected_to servers_path
81
65
  end
82
66
 
83
- it 'does not display an error message' do
67
+ it "does not display an error message" do
84
68
  assert_nil flash[:alert]
85
69
  end
86
70
  end
87
71
  end
88
72
 
89
- describe 'with an invalid server_action param' do
90
- before do
91
- params = {server_action: :bad_server_action}
92
- params = {params: params} if Rails.version.to_i >= 5
93
- patch :update_all, params
94
- end
95
-
96
- it 'redirects to servers' do
97
- assert_redirected_to servers_path
98
- end
99
-
100
- it "does not display a success message" do
101
- assert_nil flash[:notice]
102
- end
103
-
104
- it 'displays an error message' do
105
- assert_equal I18n.t(:invalid, scope: [:server, :update_all]), flash[:alert]
73
+ describe "with an invalid server_action param" do
74
+ it "gets access denied" do
75
+ assert_raises(AccessGranted::AccessDenied) do
76
+ patch :update_all, params: {server_action: :bad_server_action}
77
+ end
106
78
  end
107
79
  end
108
80
  end
109
81
 
110
- describe 'DELETE #destroy' do
111
- describe 'with a valid server id' do
82
+ describe "DELETE #destroy" do
83
+ describe "with a valid server id" do
112
84
  before do
113
- params = {id: server.id}
114
- params = {params: params} if Rails.version.to_i >= 5
115
- delete :destroy, params
85
+ delete :destroy, params: {id: server.id}
116
86
  end
117
87
 
118
- it 'redirects to servers' do
88
+ it "redirects to servers" do
119
89
  assert_redirected_to servers_path
120
90
  end
121
91
 
122
- it 'displays a flash message' do
123
- assert_equal I18n.t(:success, scope: [:server, :destroy]), flash[:notice]
92
+ it "displays a flash message" do
93
+ assert_equal I18n.t(:success, scope: %i[server destroy]), flash[:notice]
124
94
  end
125
95
 
126
- it 'destroys the server' do
96
+ it "destroys the server" do
127
97
  refute RocketJob::Server.where(id: server.id).exists?
128
98
  end
129
99
  end
130
100
 
131
- describe 'when the server is not found' do
101
+ describe "when the server is not found" do
132
102
  before do
133
- params = {id: 999999}
134
- params = {params: params} if Rails.version.to_i >= 5
135
- delete :destroy, params
103
+ delete :destroy, params: {id: 999_999}
136
104
  end
137
105
 
138
- it 'redirects to servers' do
106
+ it "redirects to servers" do
139
107
  assert_redirected_to servers_path
140
108
  end
141
109
 
142
- it 'displays a flash message' do
143
- assert_equal I18n.t(:failure, scope: [:server, :find], id: 999999), flash[:alert]
110
+ it "displays a flash message" do
111
+ assert_equal I18n.t(:failure, scope: %i[server find], id: 999_999), flash[:alert]
144
112
  end
145
113
  end
146
114
  end
147
115
 
148
116
  ([:index] + server_states).each do |state|
149
117
  describe "GET ##{state}" do
150
- describe 'html' do
118
+ describe "html" do
151
119
  describe "with no #{state} servers" do
152
120
  before do
153
121
  get state
154
122
  end
155
123
 
156
- it 'succeeds' do
124
+ it "succeeds" do
157
125
  assert_response :success
158
126
  end
159
127
 
160
- it 'renders template' do
128
+ it "renders template" do
161
129
  assert_template :index
162
130
  end
163
131
  end
@@ -168,23 +136,23 @@ module RocketJobMissionControl
168
136
  get state
169
137
  end
170
138
 
171
- it 'succeeds' do
139
+ it "succeeds" do
172
140
  assert_response :success
173
141
  end
174
142
 
175
- it 'renders template' do
143
+ it "renders template" do
176
144
  assert_template :index
177
145
  end
178
146
  end
179
147
  end
180
148
 
181
- describe 'json' do
149
+ describe "json" do
182
150
  describe "with no #{state} server" do
183
151
  before do
184
152
  get state, format: :json
185
153
  end
186
154
 
187
- it 'succeeds' do
155
+ it "succeeds" do
188
156
  assert_response :success
189
157
  json = JSON.parse(response.body)
190
158
  expected = {
@@ -203,7 +171,7 @@ module RocketJobMissionControl
203
171
  get state, format: :json
204
172
  end
205
173
 
206
- it 'succeeds' do
174
+ it "succeeds" do
207
175
  assert_response :success
208
176
  json = JSON.parse(response.body)
209
177
  expected_data = {
@@ -212,7 +180,7 @@ module RocketJobMissionControl
212
180
  "1" => "0/10",
213
181
  "2" => /s ago/,
214
182
  "3" => /s ago/,
215
- "4" => /\/servers\/#{RocketJob::Server.starting.first.id}\/stop/,
183
+ "4" => %r{/servers/#{RocketJob::Server.starting.first.id}/stop},
216
184
  "DT_RowClass" => "card callout callout-info"
217
185
  },
218
186
  running: {
@@ -220,7 +188,7 @@ module RocketJobMissionControl
220
188
  "1" => "0/10",
221
189
  "2" => /s ago/,
222
190
  "3" => /s ago/,
223
- "4" => /\/servers\/#{RocketJob::Server.running.first.id}\/stop/,
191
+ "4" => %r{/servers/#{RocketJob::Server.running.first.id}/stop},
224
192
  "DT_RowClass" => "card callout callout-success"
225
193
  },
226
194
  paused: {
@@ -228,7 +196,7 @@ module RocketJobMissionControl
228
196
  "1" => "0/10",
229
197
  "2" => /s ago/,
230
198
  "3" => /s ago/,
231
- "4" => /\/servers\/#{RocketJob::Server.paused.first.id}\/stop/,
199
+ "4" => %r{/servers/#{RocketJob::Server.paused.first.id}/stop},
232
200
  "DT_RowClass" => "card callout callout-warning"
233
201
  },
234
202
  stopping: {
@@ -236,30 +204,29 @@ module RocketJobMissionControl
236
204
  "1" => "0/10",
237
205
  "2" => /s ago/,
238
206
  "3" => /s ago/,
239
- "4" => /\/servers\/#{RocketJob::Server.stopping.first.id}/,
207
+ "4" => %r{/servers/#{RocketJob::Server.stopping.first.id}},
240
208
  "DT_RowClass" => "card callout callout-alert"
241
209
  }
242
210
  }
243
211
 
244
212
  if state == :index
245
- assert_equal 0, json['draw']
246
- assert_equal 4, json['recordsTotal']
247
- assert_equal 4, json['recordsFiltered']
248
- compare_array_of_hashes [expected_data[:starting], expected_data[:running], expected_data[:paused], expected_data[:stopping]], json['data']
213
+ assert_equal 0, json["draw"]
214
+ assert_equal 4, json["recordsTotal"]
215
+ assert_equal 4, json["recordsFiltered"]
216
+ compare_array_of_hashes [expected_data[:starting], expected_data[:running], expected_data[:paused], expected_data[:stopping]], json["data"]
249
217
  else
250
- assert_equal 0, json['draw']
251
- assert_equal 1, json['recordsTotal']
252
- assert_equal 1, json['recordsFiltered']
253
- compare_hash expected_data[state], json['data'].first
218
+ assert_equal 0, json["draw"]
219
+ assert_equal 1, json["recordsTotal"]
220
+ assert_equal 1, json["recordsFiltered"]
221
+ compare_hash expected_data[state], json["data"].first
254
222
  end
255
223
  end
256
224
  end
257
225
  end
258
-
259
226
  end
260
227
  end
261
228
 
262
- describe 'role base authentication control' do
229
+ describe "role base authentication control" do
263
230
  %i[index starting running paused stopping zombie].each do |method|
264
231
  it "#{method} has read access as default" do
265
232
  get method, format: :json
@@ -268,17 +235,15 @@ module RocketJobMissionControl
268
235
  end
269
236
 
270
237
  %i[stop pause resume destroy].each do |method|
271
- describe "#{method}" do
238
+ describe method.to_s do
272
239
  before do
273
240
  server.pause! if method == :resume
274
- @params = {id: server.id}
275
- @params = {params: @params} if Rails.version.to_i >= 5
276
241
  end
277
242
 
278
243
  %i[admin editor operator].each do |role|
279
244
  it "redirects with #{method} method and role #{role}" do
280
245
  set_role(role)
281
- patch method, @params
246
+ patch method, params: {id: server.id}
282
247
  assert_response(:redirect)
283
248
  end
284
249
  end
@@ -287,7 +252,7 @@ module RocketJobMissionControl
287
252
  it "raises authentication error for #{role}" do
288
253
  set_role(role)
289
254
  assert_raises AccessGranted::AccessDenied do
290
- patch method, @params
255
+ patch method, params: {id: server.id}
291
256
  end
292
257
  end
293
258
  end
@@ -297,11 +262,9 @@ module RocketJobMissionControl
297
262
  RocketJobMissionControl::ServersController::VALID_ACTIONS.each do |server_action|
298
263
  describe "with '#{server_action}' as the server_action param" do
299
264
  %i[admin editor operator].each do |role|
300
- it 'redirects to servers' do
265
+ it "redirects to servers" do
301
266
  set_role(role)
302
- params = {server_action: server_action}
303
- params = {params: params} if Rails.version.to_i >= 5
304
- patch :update_all, params
267
+ patch :update_all, params: {server_action: server_action}
305
268
 
306
269
  assert_response(:redirect)
307
270
  end
@@ -312,9 +275,9 @@ module RocketJobMissionControl
312
275
  end
313
276
 
314
277
  def set_role(r)
315
- Config.authorization_callback = -> do
278
+ Config.authorization_callback = lambda {
316
279
  {roles: [r]}
317
- end
280
+ }
318
281
  end
319
282
  end
320
- end
283
+ end
@@ -1,41 +1,40 @@
1
- require_relative '../../test_helper'
1
+ require_relative "../../test_helper"
2
2
 
3
3
  module RocketJobMissionControl
4
4
  class ApplicationHelperTest < ActionView::TestCase
5
5
  describe ApplicationHelper do
6
-
7
- describe '#state_icon' do
6
+ describe "#state_icon" do
8
7
  RocketJobMissionControl::ApplicationHelper::STATE_ICON_MAP.each do |state, expected_class|
9
8
  describe "when the job state is #{state}" do
10
- it 'returns the correct class' do
9
+ it "returns the correct class" do
11
10
  assert_equal "#{expected_class} #{state}", state_icon(state)
12
11
  end
13
12
  end
14
13
  end
15
14
  end
16
15
 
17
- describe '#pretty_print_array_or_hash' do
16
+ describe "#pretty_print_array_or_hash" do
18
17
  let(:arguments) { [42, "muad'dib"] }
19
18
  let(:helper_output) { pretty_print_array_or_hash(arguments) }
20
19
 
21
- describe 'when arguments is a simple array' do
22
- it 'returns a string with spacing and line breaks' do
20
+ describe "when arguments is a simple array" do
21
+ it "returns a string with spacing and line breaks" do
23
22
  assert_equal "[<br /> 42,<br /> \"muad'dib\"<br />]", helper_output
24
23
  end
25
24
  end
26
25
 
27
- describe 'when arguments is an array with complex data' do
28
- let(:arguments) {
26
+ describe "when arguments is an array with complex data" do
27
+ let(:arguments) do
29
28
  [
30
29
  42,
31
30
  {
32
- crew: ['leela', 'fry', 'bender'],
33
- created_at: '1999-03-28',
31
+ crew: %w[leela fry bender],
32
+ created_at: "1999-03-28"
34
33
  }
35
34
  ]
36
- }
35
+ end
37
36
 
38
- it 'returns a string with spacing and line breaks' do
37
+ it "returns a string with spacing and line breaks" do
39
38
  expected_output = "[<br /> 42,<br /> {<br /> \"crew\": [<br /> \"leela\",<br /> \"fry\",<br /> \"bender\"<br /> ],<br /> \"created_at\": \"1999-03-28\"<br /> }<br />]"
40
39
  assert_equal expected_output, helper_output
41
40
  end
@@ -44,7 +43,7 @@ module RocketJobMissionControl
44
43
  describe "when arguments isn't an array or hash" do
45
44
  let(:arguments) { 42 }
46
45
 
47
- it 'returns the arguments' do
46
+ it "returns the arguments" do
48
47
  assert_equal arguments, helper_output
49
48
  end
50
49
  end
@@ -1,62 +1,62 @@
1
- require_relative '../../test_helper'
1
+ require_relative "../../test_helper"
2
2
 
3
3
  module RocketJobMissionControl
4
4
  JobsHelper.include(RocketJobMissionControl::ApplicationHelper)
5
5
 
6
6
  class JobsHelperTest < ActionView::TestCase
7
7
  describe JobsHelper do
8
- describe '#jobs_icon' do
8
+ describe "#jobs_icon" do
9
9
  let :job do
10
10
  RocketJob::Jobs::SimpleJob.new
11
11
  end
12
12
 
13
- it 'shows queued' do
14
- assert_equal 'fas fa-inbox queued', job_icon(job)
13
+ it "shows queued" do
14
+ assert_equal "fas fa-inbox queued", job_icon(job)
15
15
  end
16
16
 
17
- it 'shows running' do
17
+ it "shows running" do
18
18
  job.start
19
- job.worker_name = 'test_worker'
20
- assert_equal 'fas fa-play running', job_icon(job)
19
+ job.worker_name = "test_worker"
20
+ assert_equal "fas fa-play running", job_icon(job)
21
21
  end
22
22
 
23
- it 'shows sleeping' do
23
+ it "shows sleeping" do
24
24
  job.start
25
- assert_equal 'fas fa-hourglass sleeping', job_icon(job)
25
+ assert_equal "fas fa-hourglass sleeping", job_icon(job)
26
26
  end
27
27
 
28
- it 'shows failed' do
28
+ it "shows failed" do
29
29
  job.start
30
30
  job.fail
31
- assert_equal 'fas fa-exclamation-triangle failed', job_icon(job)
31
+ assert_equal "fas fa-exclamation-triangle failed", job_icon(job)
32
32
  end
33
33
 
34
- it 'shows aborted' do
34
+ it "shows aborted" do
35
35
  job.start
36
36
  job.abort
37
- assert_equal 'fas fa-stop aborted', job_icon(job)
37
+ assert_equal "fas fa-stop aborted", job_icon(job)
38
38
  end
39
39
 
40
- it 'handles scheduled special case' do
40
+ it "handles scheduled special case" do
41
41
  job.run_at = 1.day.from_now
42
- assert_equal 'fas fa-clock scheduled', job_icon(job)
42
+ assert_equal "fas fa-clock scheduled", job_icon(job)
43
43
  end
44
44
  end
45
45
 
46
- describe '#jobs_states' do
47
- it 'returns the states' do
48
- assert_equal %w(queued running completed paused failed aborted), job_states
46
+ describe "#jobs_states" do
47
+ it "returns the states" do
48
+ assert_equal %w[queued running completed paused failed aborted], job_states
49
49
  end
50
50
  end
51
51
 
52
- describe '#job_states_with_scheduled' do
53
- it 'returns the states with scheduled' do
54
- assert_equal %w(scheduled queued running completed paused failed aborted), job_states_with_scheduled
52
+ describe "#job_states_with_scheduled" do
53
+ it "returns the states with scheduled" do
54
+ assert_equal %w[scheduled queued running completed paused failed aborted], job_states_with_scheduled
55
55
  end
56
56
  end
57
57
 
58
- describe '#job_counts_by_state' do
59
- it 'returns job counts for a state' do
58
+ describe "#job_counts_by_state" do
59
+ it "returns job counts for a state" do
60
60
  RocketJob::Job.delete_all
61
61
  RocketJob::Jobs::SimpleJob.create!
62
62
  assert_equal 1, job_counts_by_state(:queued), RocketJob::Job.counts_by_state
@@ -64,25 +64,25 @@ module RocketJobMissionControl
64
64
  end
65
65
  end
66
66
 
67
- describe '#job_action_link' do
68
- let(:action) { 'abort' }
67
+ describe "#job_action_link" do
68
+ let(:action) { "abort" }
69
69
  let(:http_method) { :patch }
70
70
  let(:path) { "/jobs/42/#{action}" }
71
71
  let(:action_link) { job_action_link(action, path, http_method) }
72
72
 
73
- it 'uses the action as the label' do
74
- assert_match />abort<\/a>/, action_link
73
+ it "uses the action as the label" do
74
+ assert_match %r{>abort</a>}, action_link
75
75
  end
76
76
 
77
- it 'links to the correct url' do
78
- assert_match /href="\/jobs\/42\/abort\"/, action_link
77
+ it "links to the correct url" do
78
+ assert_match %r{href="/jobs/42/abort\"}, action_link
79
79
  end
80
80
 
81
- it 'adds prompt for confirmation' do
81
+ it "adds prompt for confirmation" do
82
82
  assert_match /data-confirm="Are you sure you want to abort this job\?"/, action_link
83
83
  end
84
84
 
85
- it 'uses correct http method' do
85
+ it "uses correct http method" do
86
86
  assert_match /data-method="patch"/, action_link
87
87
  end
88
88
  end