rocketjob_mission_control 4.3.0 → 5.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,7 +1,7 @@
1
1
  module RocketJobMissionControl
2
2
  module PaginationHelper
3
3
  def page_nav_disabled_class(current_position, boundary)
4
- current_position.to_i == boundary.to_i ? 'disabled' : ''
4
+ current_position.to_i == boundary.to_i ? "disabled" : ""
5
5
  end
6
6
  end
7
7
  end
@@ -7,7 +7,7 @@ module RocketJobMissionControl
7
7
  def server_icon(server)
8
8
  state =
9
9
  if server.zombie?
10
- 'zombie'
10
+ "zombie"
11
11
  else
12
12
  server.state
13
13
  end
@@ -16,14 +16,14 @@ module RocketJobMissionControl
16
16
 
17
17
  def server_card_class(server)
18
18
  if server.zombie?
19
- 'callout-zombie'
19
+ "callout-zombie"
20
20
  else
21
21
  map = {
22
- running: 'callout-success',
23
- paused: 'callout-warning',
24
- stopping: 'callout-alert',
22
+ running: "callout-success",
23
+ paused: "callout-warning",
24
+ stopping: "callout-alert"
25
25
  }
26
- map[server.state] || 'callout-info'
26
+ map[server.state] || "callout-info"
27
27
  end
28
28
  end
29
29
  end
@@ -1,9 +1,7 @@
1
1
  module RocketJobMissionControl
2
2
  module SlicesHelper
3
-
4
- def display_slice_info(slice, encrypted=false)
5
- encrypted ? 'encrypted' : pretty_print_array_or_hash(slice.to_a)
3
+ def display_slice_info(slice, encrypted = false)
4
+ encrypted ? "encrypted" : pretty_print_array_or_hash(slice.to_a)
6
5
  end
7
-
8
6
  end
9
7
  end
@@ -17,7 +17,7 @@ module RocketJobMissionControl
17
17
 
18
18
  # Stop, Pause, Resume, Destroy (force stop) Rocket Job Servers
19
19
  role :operator, {operator: true} do
20
- can %i[stop kill pause resume destroy update_all], RocketJob::Server
20
+ can %i[stop kill pause resume destroy destroy_zombies thread_dump], RocketJob::Server
21
21
  end
22
22
 
23
23
  # Pause, Resume, Retry, Abort, Edit Jobs
@@ -47,4 +47,3 @@ module RocketJobMissionControl
47
47
  end
48
48
  end
49
49
  end
50
-
@@ -1,12 +1,13 @@
1
1
  module RocketJobMissionControl
2
2
  class Authorization
3
- ROLES = %i[admin editor operator manager dirmon user view]
3
+ ROLES = %i[admin editor operator manager dirmon user view].freeze
4
4
  attr_accessor *ROLES
5
5
  attr_accessor :login
6
6
 
7
7
  def initialize(roles: [], login: nil)
8
8
  @login = login
9
9
  return if roles.blank?
10
+
10
11
  invalid_roles = roles - ROLES
11
12
  raise(ArgumentError, "Invalid Roles Supplied: #{invalid_roles.inspect}") unless invalid_roles.empty?
12
13
 
@@ -19,4 +20,4 @@ module RocketJobMissionControl
19
20
  roles.each { |role| public_send("#{role}=", true) }
20
21
  end
21
22
  end
22
- end
23
+ end
@@ -1,6 +1,5 @@
1
1
  module RocketJobMissionControl
2
2
  module JobSanitizer
3
-
4
3
  # Returns [Hash] the permissible params for the specified job class, after sanitizing.
5
4
  # Parameters
6
5
  # properties [Hash]
@@ -19,29 +18,27 @@ module RocketJobMissionControl
19
18
  def self.sanitize(properties, job_class, target, nil_blank = true)
20
19
  permissible_params = {}
21
20
  job_class.user_editable_fields.each do |field_name|
22
- if value = properties[field_name]
23
- field = job_class.fields[field_name.to_s]
24
- next unless field && field.type
21
+ next unless value = properties[field_name]
25
22
 
26
- case field.type.name
27
- when 'Hash'
28
- begin
29
- value = value.blank? ? nil : JSON.parse(value)
30
- rescue JSON::ParserError => e
31
- target.errors.add(:properties, e.message)
32
- end
33
- end
23
+ field = job_class.fields[field_name.to_s]
24
+ next unless field&.type
34
25
 
35
- if value.blank? && !value.is_a?(Hash)
36
- permissible_params[field_name] = nil if nil_blank
37
- else
38
- permissible_params[field_name] = value
26
+ case field.type.name
27
+ when "Hash"
28
+ begin
29
+ value = value.blank? ? nil : JSON.parse(value)
30
+ rescue JSON::ParserError => e
31
+ target.errors.add(:properties, e.message)
39
32
  end
33
+ end
40
34
 
35
+ if value.blank? && !value.is_a?(Hash)
36
+ permissible_params[field_name] = nil if nil_blank
37
+ else
38
+ permissible_params[field_name] = value
41
39
  end
42
40
  end
43
41
  permissible_params
44
42
  end
45
-
46
43
  end
47
44
  end
@@ -42,16 +42,13 @@ module RocketJobMissionControl
42
42
  records = records.where(search_columns.first => regexp)
43
43
  else
44
44
  cols = search_columns.collect { |col| {col => regexp} }
45
- records = records.where('$or' => cols)
45
+ records = records.where("$or" => cols)
46
46
  end
47
47
  end
48
48
 
49
49
  # Pagination
50
- if start && page_size
51
- records = records.skip(start).limit(page_size)
52
- end
50
+ records = records.skip(start).limit(page_size) if start && page_size
53
51
  records
54
52
  end
55
-
56
53
  end
57
54
  end
@@ -22,7 +22,7 @@
22
22
  <% if can?(:view_slice, @job) %>
23
23
  <th>
24
24
  <div>
25
- <%= link_to 'View Slice', view_slice_job_path(@job, error_type: exception.class_name, record_number: @job.input.failed.first["exception"]["record_number"] ), class: 'btn btn-primary' %>
25
+ <%= link_to 'View Slice', view_slice_job_path(@job, error_type: exception.class_name, record_number: @job.input.failed.first.processing_record_number), class: 'btn btn-primary' %>
26
26
  </div>
27
27
  </th>
28
28
  <% end %>
@@ -15,7 +15,7 @@
15
15
  <div id='submit'>
16
16
  <%= f.submit 'Save', class: 'btn btn-primary' %>
17
17
  <%= link_to 'Delete', delete_line_job_path(@job, offset: @offset, error_type: @failure_exception.class_name, line_index: @line_index), :data => {:confirm => 'Are you sure?'}, method: :patch, class: 'btn btn-danger' %>
18
- <%= link_to 'Cancel', view_slice_job_path(@job, error_type: @failure_exception.class_name, record_number: @job.input.failed.first["exception"]["record_number"]), class: 'btn btn-default' %>
18
+ <%= link_to 'Cancel', view_slice_job_path(@job, error_type: @failure_exception.class_name, record_number: @job.input.failed.first.processing_record_number), class: 'btn btn-default' %>
19
19
  <% end %>
20
20
 
21
21
  </div>
@@ -11,8 +11,8 @@
11
11
  <div class='server-collection-actions'>
12
12
  <ol>
13
13
  <div class='btn-group'>
14
- <% if can?(:update_all, RocketJob::Server) %>
15
- <% Array(@actions).each do |action| %>
14
+ <% Array(@actions).each do |action| %>
15
+ <% if can?(action, RocketJob::Server) %>
16
16
  <%= link_to(
17
17
  "#{action.to_s.humanize.capitalize}",
18
18
  rocket_job_mission_control.update_all_servers_path(server_action: action),
@@ -1,13 +1,11 @@
1
- Rails.application.config.assets.precompile << Proc.new { |path|
2
- if path =~ /\.(eot|svg|ttf|woff)\z/
3
- true
4
- end
5
- }
1
+ Rails.application.config.assets.precompile << proc do |path|
2
+ true if path =~ /\.(eot|svg|ttf|woff)\z/
3
+ end
6
4
 
7
- Rails.application.config.assets.precompile += %w(
5
+ Rails.application.config.assets.precompile += %w[
8
6
  rocket_job_mission_control/favicon.png
9
7
  rocket_job_mission_control/safari-pinned-tab.svg
10
8
  rocket_job_mission_control/favicon-16x16.png
11
9
  rocket_job_mission_control/favicon-32x32.png
12
10
  rocket_job_mission_control/apple-touch-icon.png
13
- )
11
+ ]
@@ -50,7 +50,10 @@ en:
50
50
  failure: "Error attempting to resume server."
51
51
  update_all:
52
52
  invalid: "Action not allowed."
53
+ success: "Submitted %{action} request to all active Rocket Job servers."
53
54
  confirm: "Are you sure you want to %{action} ALL Rocket Job servers?"
55
+ update_one:
56
+ success: "Submitted %{action} request to Rocket Job server: %{name}."
54
57
  job:
55
58
  find:
56
59
  failure: "Could not find job with id: %{id}!"
@@ -1,15 +1,14 @@
1
- #@formatter:off
1
+ # @formatter:off
2
2
  RocketJobMissionControl::Engine.routes.draw do
3
-
4
- resources :jobs, only: [:index, :show, :update, :destroy, :edit] do
3
+ resources :jobs, only: %i[index show update destroy edit] do
5
4
  collection do
6
- get :running, to: 'jobs#running'
7
- get :scheduled, to: 'jobs#scheduled'
8
- get :completed, to: 'jobs#completed'
9
- get :queued, to: 'jobs#queued'
10
- get :paused, to: 'jobs#paused'
11
- get :failed, to: 'jobs#failed'
12
- get :aborted, to: 'jobs#aborted'
5
+ get :running, to: "jobs#running"
6
+ get :scheduled, to: "jobs#scheduled"
7
+ get :completed, to: "jobs#completed"
8
+ get :queued, to: "jobs#queued"
9
+ get :paused, to: "jobs#paused"
10
+ get :failed, to: "jobs#failed"
11
+ get :aborted, to: "jobs#aborted"
13
12
  end
14
13
 
15
14
  member do
@@ -30,13 +29,13 @@ RocketJobMissionControl::Engine.routes.draw do
30
29
 
31
30
  resources :active_workers, only: :index
32
31
 
33
- resources :servers, only: [:index, :destroy] do
32
+ resources :servers, only: %i[index destroy] do
34
33
  collection do
35
- get :starting, to: 'servers#starting'
36
- get :running, to: 'servers#running'
37
- get :paused, to: 'servers#paused'
38
- get :stopping, to: 'servers#stopping'
39
- get :zombie, to: 'servers#zombie'
34
+ get :starting, to: "servers#starting"
35
+ get :running, to: "servers#running"
36
+ get :paused, to: "servers#paused"
37
+ get :stopping, to: "servers#stopping"
38
+ get :zombie, to: "servers#zombie"
40
39
  end
41
40
 
42
41
  member do
@@ -51,10 +50,10 @@ RocketJobMissionControl::Engine.routes.draw do
51
50
 
52
51
  resources :dirmon_entries do
53
52
  collection do
54
- get :pending, to: 'dirmon_entries#pending'
55
- get :enabled, to: 'dirmon_entries#enabled'
56
- get :failed, to: 'dirmon_entries#failed'
57
- get :disabled, to: 'dirmon_entries#disabled'
53
+ get :pending, to: "dirmon_entries#pending"
54
+ get :enabled, to: "dirmon_entries#enabled"
55
+ get :failed, to: "dirmon_entries#failed"
56
+ get :disabled, to: "dirmon_entries#disabled"
58
57
  end
59
58
 
60
59
  member do
@@ -63,7 +62,7 @@ RocketJobMissionControl::Engine.routes.draw do
63
62
  end
64
63
  end
65
64
 
66
- get 'rocket_job_mission_control/test' => 'test#index' if Rails.env.test?
65
+ get "rocket_job_mission_control/test" => "test#index" if Rails.env.test?
67
66
 
68
67
  root to: "jobs#running"
69
68
  end
@@ -1,5 +1,4 @@
1
1
  module RocketJobMissionControl
2
-
3
2
  # The authorization callback
4
3
  module Config
5
4
  mattr_accessor :authorization_callback
@@ -8,22 +7,22 @@ module RocketJobMissionControl
8
7
  class Engine < ::Rails::Engine
9
8
  isolate_namespace RocketJobMissionControl
10
9
 
11
- require 'rocketjob'
12
- require 'jquery-rails'
13
- require 'sass-rails'
14
- require 'jquery-datatables-rails'
15
- require 'access-granted'
10
+ require "rocketjob"
11
+ require "jquery-rails"
12
+ require "sass-rails"
13
+ require "jquery-datatables-rails"
14
+ require "access-granted"
16
15
  begin
17
- require 'rocketjob_enterprise'
16
+ require "rocketjob_enterprise"
18
17
  rescue LoadError
19
18
  end
20
19
 
21
20
  config.rocket_job_mission_control = ::RocketJobMissionControl::Config
22
21
 
23
22
  config.to_prepare do
24
- Rails.application.config.assets.precompile += %w(
23
+ Rails.application.config.assets.precompile += %w[
25
24
  rocket_job_mission_control/rocket-icon-64x64.png
26
- )
25
+ ]
27
26
  end
28
27
  end
29
28
  end
@@ -1,3 +1,3 @@
1
1
  module RocketJobMissionControl
2
- VERSION = '4.3.0'.freeze
2
+ VERSION = "5.0.0.beta1".freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'rocket_job_mission_control/engine'
1
+ require "rocket_job_mission_control/engine"
2
2
 
3
3
  module RocketJobMissionControl
4
4
  end
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  def compare_hash(expected_hash, actual_hash)
8
8
  expected_hash.each_pair do |key, expected|
9
- actual = actual_hash[key]
9
+ actual = actual_hash[key].to_s
10
10
  if expected.is_a?(Regexp)
11
11
  assert_match expected, actual, "#{key} does not match. Expected #{expected.inspect}. Actual #{actual.inspect}"
12
12
  else
@@ -14,4 +14,3 @@ def compare_hash(expected_hash, actual_hash)
14
14
  end
15
15
  end
16
16
  end
17
-
@@ -1,40 +1,40 @@
1
- require_relative '../../test_helper'
1
+ require_relative "../../test_helper"
2
2
 
3
3
  module RocketJobMissionControl
4
4
  class TestController < ApplicationController
5
5
  def index
6
6
  @time_zone = Time.zone
7
7
 
8
- render plain: 'Time Zoned'
8
+ render plain: "Time Zoned"
9
9
  end
10
10
  end
11
11
 
12
12
  class ApplicationControllerTest < ActionController::TestCase
13
13
  describe TestController do
14
- describe '#with_time_zone' do
15
- it 'uses correct timezone with session and time_zone set' do
14
+ describe "#with_time_zone" do
15
+ it "uses correct timezone with session and time_zone set" do
16
16
  if Rails.version.to_i >= 5
17
- session['time_zone'] = 'America/Los_Angeles'
17
+ session["time_zone"] = "America/Los_Angeles"
18
18
  get :index
19
19
  else
20
- get :index, {}, {'time_zone' => 'America/Los_Angeles'}
20
+ get :index, {}, {"time_zone" => "America/Los_Angeles"}
21
21
  end
22
- assert_equal 'America/Los_Angeles', assigns(:time_zone).name
22
+ assert_equal "America/Los_Angeles", assigns(:time_zone).name
23
23
  end
24
24
 
25
- it 'uses correct timezone with session, but no time_zone set' do
25
+ it "uses correct timezone with session, but no time_zone set" do
26
26
  if Rails.version.to_i >= 5
27
- session['user_id'] = '42'
27
+ session["user_id"] = "42"
28
28
  get :index
29
29
  else
30
- get :index, {}, {'user_id' => '42'}
30
+ get :index, {}, {"user_id" => "42"}
31
31
  end
32
- assert_equal 'UTC', assigns(:time_zone).name
32
+ assert_equal "UTC", assigns(:time_zone).name
33
33
  end
34
34
 
35
- it 'uses correct timezone without a session' do
35
+ it "uses correct timezone without a session" do
36
36
  get :index
37
- assert_equal 'UTC', assigns(:time_zone).name
37
+ assert_equal "UTC", assigns(:time_zone).name
38
38
  end
39
39
  end
40
40
  end
@@ -1,5 +1,5 @@
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 DirmonEntriesControllerTest < ActionController::TestCase
@@ -10,14 +10,14 @@ module RocketJobMissionControl
10
10
  end
11
11
 
12
12
  let :job_class_name do
13
- 'RocketJob::Jobs::SimpleJob'
13
+ "RocketJob::Jobs::SimpleJob"
14
14
  end
15
15
 
16
16
  let :existing_dirmon_entry do
17
17
  RocketJob::DirmonEntry.create!(
18
- name: 'Test',
18
+ name: "Test",
19
19
  job_class_name: job_class_name,
20
- pattern: 'the_path'
20
+ pattern: "the_path"
21
21
  )
22
22
  end
23
23
 
@@ -26,16 +26,16 @@ module RocketJobMissionControl
26
26
  let :one_dirmon_entry_for_every_state do
27
27
  dirmon_entry_states.collect do |state|
28
28
  RocketJob::DirmonEntry.create!(
29
- name: 'Test',
29
+ name: "Test",
30
30
  job_class_name: job_class_name,
31
- pattern: 'the_path',
31
+ pattern: "the_path",
32
32
  state: state
33
33
  )
34
34
  end
35
35
  end
36
36
 
37
- describe 'PATCH #enable' do
38
- describe 'when transition is allowed' do
37
+ describe "PATCH #enable" do
38
+ describe "when transition is allowed" do
39
39
  before do
40
40
  params = {id: existing_dirmon_entry.id}
41
41
  params = {params: params} if Rails.version.to_i >= 5
@@ -46,12 +46,12 @@ module RocketJobMissionControl
46
46
  assert_redirected_to dirmon_entry_path(existing_dirmon_entry)
47
47
  end
48
48
 
49
- it 'changes the state to enabled' do
49
+ it "changes the state to enabled" do
50
50
  assert existing_dirmon_entry.reload.enabled?
51
51
  end
52
52
  end
53
53
 
54
- describe 'when transition is not allowed' do
54
+ describe "when transition is not allowed" do
55
55
  before do
56
56
  existing_dirmon_entry.enable!
57
57
  params = {id: existing_dirmon_entry.id}
@@ -59,18 +59,18 @@ module RocketJobMissionControl
59
59
  patch :enable, params
60
60
  end
61
61
 
62
- it 'succeeds' do
62
+ it "succeeds" do
63
63
  assert_response :success
64
64
  end
65
65
 
66
- it 'alerts the user' do
67
- assert_equal I18n.t(:failure, scope: [:dirmon_entry, :enable]), flash[:alert]
66
+ it "alerts the user" do
67
+ assert_equal I18n.t(:failure, scope: %i[dirmon_entry enable]), flash[:alert]
68
68
  end
69
69
  end
70
70
  end
71
71
 
72
- describe 'PATCH #disable' do
73
- describe 'when transition is allowed' do
72
+ describe "PATCH #disable" do
73
+ describe "when transition is allowed" do
74
74
  before do
75
75
  existing_dirmon_entry.enable!
76
76
  params = {id: existing_dirmon_entry.id}
@@ -82,29 +82,29 @@ module RocketJobMissionControl
82
82
  assert_redirected_to dirmon_entry_path(existing_dirmon_entry)
83
83
  end
84
84
 
85
- it 'changes the state to disabled' do
85
+ it "changes the state to disabled" do
86
86
  assert existing_dirmon_entry.reload.disabled?
87
87
  end
88
88
  end
89
89
 
90
- describe 'when transition is not allowed' do
90
+ describe "when transition is not allowed" do
91
91
  before do
92
92
  params = {id: existing_dirmon_entry.id}
93
93
  params = {params: params} if Rails.version.to_i >= 5
94
94
  patch :disable, params
95
95
  end
96
96
 
97
- it 'succeeds' do
97
+ it "succeeds" do
98
98
  assert_response :success
99
99
  end
100
100
 
101
- it 'alerts the user' do
102
- assert_equal I18n.t(:failure, scope: [:dirmon_entry, :disable]), flash[:alert]
101
+ it "alerts the user" do
102
+ assert_equal I18n.t(:failure, scope: %i[dirmon_entry disable]), flash[:alert]
103
103
  end
104
104
  end
105
105
  end
106
106
 
107
- describe 'GET #new' do
107
+ describe "GET #new" do
108
108
  let(:entry_params) { {} }
109
109
 
110
110
  before do
@@ -113,99 +113,98 @@ module RocketJobMissionControl
113
113
  get :new, params
114
114
  end
115
115
 
116
- it 'succeeds' do
116
+ it "succeeds" do
117
117
  assert_response :success
118
118
  end
119
119
 
120
- it 'assigns a new entry' do
120
+ it "assigns a new entry" do
121
121
  assert assigns(:dirmon_entry).present?
122
122
  refute assigns(:dirmon_entry).persisted?
123
123
  end
124
124
 
125
- describe 'with form params' do
126
- let(:entry_params) { {rocket_job_dirmon_entry: {name: 'new entry'}} }
125
+ describe "with form params" do
126
+ let(:entry_params) { {rocket_job_dirmon_entry: {name: "new entry"}} }
127
127
 
128
- it 'succeeds' do
128
+ it "succeeds" do
129
129
  assert_response :success
130
130
  end
131
131
 
132
- it 'assigns the params to new entry' do
133
- assert_equal 'new entry', assigns(:dirmon_entry).name
132
+ it "assigns the params to new entry" do
133
+ assert_equal "new entry", assigns(:dirmon_entry).name
134
134
  end
135
135
 
136
- describe 'with a valid job_class_name' do
137
- let(:entry_params) { {rocket_job_dirmon_entry: {job_class_name: 'NoParamsJob'}} }
136
+ describe "with a valid job_class_name" do
137
+ let(:entry_params) { {rocket_job_dirmon_entry: {job_class_name: "NoParamsJob"}} }
138
138
 
139
- it 'succeeds' do
139
+ it "succeeds" do
140
140
  assert_response :success
141
141
  end
142
142
 
143
- it 'assigns the job class' do
144
- assert_equal 'NoParamsJob', assigns(:dirmon_entry).job_class_name
143
+ it "assigns the job class" do
144
+ assert_equal "NoParamsJob", assigns(:dirmon_entry).job_class_name
145
145
  end
146
146
  end
147
147
 
148
- describe 'with an invalid job_class_name' do
149
- let(:entry_params) { {rocket_job_dirmon_entry: {job_class_name: 'BadJob'}} }
148
+ describe "with an invalid job_class_name" do
149
+ let(:entry_params) { {rocket_job_dirmon_entry: {job_class_name: "BadJob"}} }
150
150
 
151
- it 'succeeds' do
151
+ it "succeeds" do
152
152
  assert_response :success
153
153
  end
154
154
 
155
- it 'adds an error' do
155
+ it "adds an error" do
156
156
  assert assigns(:dirmon_entry).errors[:job_class_name].present?
157
157
  end
158
158
  end
159
159
  end
160
-
161
160
  end
162
161
 
163
- describe 'PATCH #update' do
164
- describe 'with valid parameters' do
162
+ describe "PATCH #update" do
163
+ describe "with valid parameters" do
165
164
  before do
166
- params = {id: existing_dirmon_entry.id, rocket_job_dirmon_entry: {pattern: 'the_path2', job_class_name: job_class_name}}
165
+ params = {id: existing_dirmon_entry.id, rocket_job_dirmon_entry: {pattern: "the_path2", job_class_name: job_class_name}}
167
166
  params = {params: params} if Rails.version.to_i >= 5
168
167
  patch :update, params
169
168
  end
170
169
 
171
- it 'redirects to the updated entry' do
170
+ it "redirects to the updated entry" do
172
171
  assert_redirected_to dirmon_entry_path(existing_dirmon_entry)
173
172
  end
174
173
 
175
- it 'updates the entry' do
176
- assert_equal 'the_path2', existing_dirmon_entry.reload.pattern
174
+ it "updates the entry" do
175
+ assert_equal "the_path2", existing_dirmon_entry.reload.pattern
177
176
  end
178
177
  end
179
178
 
180
- describe 'with invalid parameters' do
179
+ describe "with invalid parameters" do
181
180
  before do
182
- params = {id: existing_dirmon_entry.id, rocket_job_dirmon_entry: {job_class_name: 'FakeAndBadJob'}}
181
+ params = {id: existing_dirmon_entry.id, rocket_job_dirmon_entry: {job_class_name: "FakeAndBadJob"}}
183
182
  params = {params: params} if Rails.version.to_i >= 5
184
183
  patch :update, params
185
184
  end
186
185
 
187
- it 'renders the edit template' do
186
+ it "renders the edit template" do
188
187
  assert_response :success
189
188
  end
190
189
 
191
- it 'alerts the user' do
190
+ it "alerts the user" do
192
191
  if RocketJob::VERSION.to_f >= 3.5
193
- assert_select 'div.message', "job_class_name: [\"Job FakeAndBadJob must be defined and inherit from RocketJob::Job\"]"
192
+ assert_select "div.message", "job_class_name: [\"Job FakeAndBadJob must be defined and inherit from RocketJob::Job\"]"
194
193
  else
195
- assert_select 'div.message', "job_class_name: [\"job_class_name must be defined and must be derived from RocketJob::Job\"]"
194
+ assert_select "div.message", "job_class_name: [\"job_class_name must be defined and must be derived from RocketJob::Job\"]"
196
195
  end
197
196
  end
198
197
  end
199
198
  end
200
199
 
201
- describe 'POST #create' do
202
- describe 'with valid parameters' do
200
+ describe "POST #create" do
201
+ describe "with valid parameters" do
203
202
  let(:dirmon_params) do
204
203
  {
205
- name: 'Test',
206
- pattern: '/files/*',
204
+ name: "Test",
205
+ pattern: "/files/*",
207
206
  job_class_name: job_class_name,
208
- properties: {description: '', priority: '42'}
207
+ properties: {description: "", priority: "42"}
209
208
  }
210
209
  end
211
210
 
@@ -215,38 +214,38 @@ module RocketJobMissionControl
215
214
  post :create, params
216
215
  end
217
216
 
218
- it 'creates the entry' do
217
+ it "creates the entry" do
219
218
  assert assigns(:dirmon_entry).persisted?
220
219
  end
221
220
 
222
- it 'has no errors' do
221
+ it "has no errors" do
223
222
  assert assigns(:dirmon_entry).errors.messages.empty?
224
223
  end
225
224
 
226
- it 'redirects to created entry' do
225
+ it "redirects to created entry" do
227
226
  assert_redirected_to dirmon_entry_path(assigns(:dirmon_entry))
228
227
  end
229
228
 
230
- it 'does not save blank properties' do
229
+ it "does not save blank properties" do
231
230
  assert_nil assigns(:dirmon_entry).properties[:description]
232
231
  end
233
232
 
234
- it 'saves properties' do
235
- assert_equal '42', assigns(:dirmon_entry).properties[:priority]
233
+ it "saves properties" do
234
+ assert_equal "42", assigns(:dirmon_entry).properties[:priority]
236
235
  end
237
236
 
238
- [:name, :pattern, :job_class_name].each do |attribute|
237
+ %i[name pattern job_class_name].each do |attribute|
239
238
  it "assigns the correct value for #{attribute}" do
240
239
  assert_equal dirmon_params[attribute], assigns(:dirmon_entry)[attribute]
241
240
  end
242
241
  end
243
242
  end
244
243
 
245
- describe 'with invalid parameters' do
244
+ describe "with invalid parameters" do
246
245
  let(:dirmon_params) do
247
246
  {
248
- name: 'Test',
249
- job_class_name: 'FakeAndBadJob'
247
+ name: "Test",
248
+ job_class_name: "FakeAndBadJob"
250
249
  }
251
250
  end
252
251
 
@@ -256,82 +255,82 @@ module RocketJobMissionControl
256
255
  post :create, params
257
256
  end
258
257
 
259
- describe 'on model attributes' do
260
- it 'renders the new template' do
258
+ describe "on model attributes" do
259
+ it "renders the new template" do
261
260
  assert_response :success
262
261
  assert_template :new
263
262
  end
264
263
 
265
- it 'has errors on the entry' do
264
+ it "has errors on the entry" do
266
265
  refute assigns(:dirmon_entry).valid?
267
266
  end
268
267
  end
269
268
  end
270
269
  end
271
270
 
272
- describe 'GET #edit' do
271
+ describe "GET #edit" do
273
272
  before do
274
273
  params = {id: existing_dirmon_entry.id}
275
274
  params = {params: params} if Rails.version.to_i >= 5
276
275
  get :edit, params
277
276
  end
278
277
 
279
- it 'succeeds' do
278
+ it "succeeds" do
280
279
  assert_response :success
281
280
  end
282
281
 
283
- it 'assigns the entry' do
282
+ it "assigns the entry" do
284
283
  assert_equal existing_dirmon_entry, assigns(:dirmon_entry)
285
284
  end
286
285
  end
287
286
 
288
- describe 'GET #show' do
289
- describe 'with an invalid id' do
287
+ describe "GET #show" do
288
+ describe "with an invalid id" do
290
289
  before do
291
290
  params = {id: 42}
292
291
  params = {params: params} if Rails.version.to_i >= 5
293
292
  get :show, params
294
293
  end
295
294
 
296
- it 'redirects' do
295
+ it "redirects" do
297
296
  assert_redirected_to dirmon_entries_path
298
297
  end
299
298
 
300
- it 'adds a flash alert message' do
301
- assert_equal I18n.t(:failure, scope: [:dirmon_entry, :find], id: 42), flash[:alert]
299
+ it "adds a flash alert message" do
300
+ assert_equal I18n.t(:failure, scope: %i[dirmon_entry find], id: 42), flash[:alert]
302
301
  end
303
302
  end
304
303
 
305
- describe 'with a valid id' do
304
+ describe "with a valid id" do
306
305
  before do
307
306
  params = {id: existing_dirmon_entry.id}
308
307
  params = {params: params} if Rails.version.to_i >= 5
309
308
  get :show, params
310
309
  end
311
310
 
312
- it 'succeeds' do
311
+ it "succeeds" do
313
312
  assert_response :success
314
313
  end
315
314
 
316
- it 'assigns the entry' do
315
+ it "assigns the entry" do
317
316
  assert assigns(:dirmon_entry).present?
318
317
  end
319
318
  end
320
319
  end
321
320
 
322
- describe 'DELETE #destroy' do
323
- describe 'with a valid id' do
321
+ describe "DELETE #destroy" do
322
+ describe "with a valid id" do
324
323
  before do
325
324
  params = {id: existing_dirmon_entry.id}
326
325
  params = {params: params} if Rails.version.to_i >= 5
327
326
  delete :destroy, params
328
327
  end
329
328
 
330
- it 'redirects to index' do
329
+ it "redirects to index" do
331
330
  assert_redirected_to dirmon_entries_path
332
331
  end
333
332
 
334
- it 'deletes the entry' do
333
+ it "deletes the entry" do
335
334
  refute RocketJob::DirmonEntry.where(id: existing_dirmon_entry.id).exists?
336
335
  end
337
336
  end
@@ -339,17 +338,17 @@ module RocketJobMissionControl
339
338
 
340
339
  ([:index] + dirmon_entry_states).each do |state|
341
340
  describe "GET ##{state}" do
342
- describe 'html' do
341
+ describe "html" do
343
342
  describe "with no #{state} entries" do
344
343
  before do
345
344
  get state
346
345
  end
347
346
 
348
- it 'succeeds' do
347
+ it "succeeds" do
349
348
  assert_response :success
350
349
  end
351
350
 
352
- it 'renders template' do
351
+ it "renders template" do
353
352
  assert_template :index
354
353
  end
355
354
  end
@@ -360,23 +359,23 @@ module RocketJobMissionControl
360
359
  get state
361
360
  end
362
361
 
363
- it 'succeeds' do
362
+ it "succeeds" do
364
363
  assert_response :success
365
364
  end
366
365
 
367
- it 'renders template' do
366
+ it "renders template" do
368
367
  assert_template :index
369
368
  end
370
369
  end
371
370
  end
372
371
 
373
- describe 'json' do
372
+ describe "json" do
374
373
  describe "with #{state} entries" do
375
374
  before do
376
375
  get state, format: :json
377
376
  end
378
377
 
379
- it 'succeeds' do
378
+ it "succeeds" do
380
379
  assert_response :success
381
380
  json = JSON.parse(response.body)
382
381
  expected = {
@@ -395,7 +394,7 @@ module RocketJobMissionControl
395
394
  get state, format: :json
396
395
  end
397
396
 
398
- it 'succeeds' do
397
+ it "succeeds" do
399
398
  assert_response :success
400
399
  json = JSON.parse(response.body)
401
400
  expected_data = {
@@ -426,15 +425,15 @@ module RocketJobMissionControl
426
425
  }
427
426
 
428
427
  if state == :index
429
- assert_equal 0, json['draw']
430
- assert_equal 4, json['recordsTotal']
431
- assert_equal 4, json['recordsFiltered']
432
- assert_equal [expected_data[:pending], expected_data[:enabled], expected_data[:failed], expected_data[:disabled]], json['data']
428
+ assert_equal 0, json["draw"]
429
+ assert_equal 4, json["recordsTotal"]
430
+ assert_equal 4, json["recordsFiltered"]
431
+ assert_equal [expected_data[:pending], expected_data[:enabled], expected_data[:failed], expected_data[:disabled]], json["data"]
433
432
  else
434
- assert_equal 0, json['draw']
435
- assert_equal 1, json['recordsTotal']
436
- assert_equal 1, json['recordsFiltered']
437
- assert_equal [expected_data[state]], json['data']
433
+ assert_equal 0, json["draw"]
434
+ assert_equal 1, json["recordsTotal"]
435
+ assert_equal 1, json["recordsFiltered"]
436
+ assert_equal [expected_data[state]], json["data"]
438
437
  end
439
438
  end
440
439
  end
@@ -442,13 +441,13 @@ module RocketJobMissionControl
442
441
  end
443
442
  end
444
443
 
445
- describe 'role base authentication control' do
444
+ describe "role base authentication control" do
446
445
  let(:dirmon_params) do
447
446
  {
448
- name: 'Test',
449
- pattern: '/files/*',
447
+ name: "Test",
448
+ pattern: "/files/*",
450
449
  job_class_name: job_class_name,
451
- properties: {description: '', priority: '42'}
450
+ properties: {description: "", priority: "42"}
452
451
  }
453
452
  end
454
453
 
@@ -477,7 +476,7 @@ module RocketJobMissionControl
477
476
 
478
477
  # POST
479
478
  %i[admin editor operator manager dirmon].each do |role|
480
- it 'creates dirmon entry' do
479
+ it "creates dirmon entry" do
481
480
  set_role(role)
482
481
  params = {rocket_job_dirmon_entry: dirmon_params}
483
482
  params = {params: params} if Rails.version.to_i >= 5
@@ -487,7 +486,7 @@ module RocketJobMissionControl
487
486
  end
488
487
  end
489
488
 
490
- it 'deletes dirmon entry' do
489
+ it "deletes dirmon entry" do
491
490
  set_role(:admin)
492
491
  params = {id: existing_dirmon_entry.id}
493
492
  params = {params: params} if Rails.version.to_i >= 5
@@ -510,9 +509,9 @@ module RocketJobMissionControl
510
509
  end
511
510
 
512
511
  def set_role(r)
513
- Config.authorization_callback = -> do
512
+ Config.authorization_callback = lambda {
514
513
  {roles: [r]}
515
- end
514
+ }
516
515
  end
517
516
  end
518
517
  end