rocketjob_mission_control 3.0.0.rc1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +10 -6
  3. data/app/assets/javascripts/rocket_job_mission_control/application.js +4 -3
  4. data/app/assets/javascripts/rocket_job_mission_control/base.js +12 -0
  5. data/app/assets/javascripts/rocket_job_mission_control/datatable.js +40 -0
  6. data/app/assets/javascripts/rocket_job_mission_control/dirmon_entries.js +16 -0
  7. data/app/assets/javascripts/rocket_job_mission_control/selectize.js +6 -0
  8. data/app/controllers/rocket_job_mission_control/active_workers_controller.rb +16 -5
  9. data/app/controllers/rocket_job_mission_control/application_controller.rb +2 -0
  10. data/app/controllers/rocket_job_mission_control/dirmon_entries_controller.rb +47 -67
  11. data/app/controllers/rocket_job_mission_control/jobs_controller.rb +113 -19
  12. data/app/controllers/rocket_job_mission_control/servers_controller.rb +71 -28
  13. data/app/datatables/rocket_job_mission_control/abstract_datatable.rb +3 -3
  14. data/app/datatables/rocket_job_mission_control/active_workers_datatable.rb +8 -14
  15. data/app/datatables/rocket_job_mission_control/dirmon_entries_datatable.rb +7 -15
  16. data/app/datatables/rocket_job_mission_control/jobs_datatable.rb +128 -13
  17. data/app/datatables/rocket_job_mission_control/servers_datatable.rb +13 -15
  18. data/app/helpers/rocket_job_mission_control/application_helper.rb +58 -0
  19. data/app/helpers/rocket_job_mission_control/jobs_helper.rb +15 -7
  20. data/app/helpers/rocket_job_mission_control/servers_helper.rb +1 -1
  21. data/app/models/rocket_job_mission_control/job_sanitizer.rb +47 -0
  22. data/app/models/rocket_job_mission_control/query.rb +24 -18
  23. data/app/views/layouts/rocket_job_mission_control/application.html.erb +43 -0
  24. data/app/views/layouts/rocket_job_mission_control/partials/_flash.html.erb +20 -0
  25. data/app/views/layouts/rocket_job_mission_control/partials/_header.html.erb +45 -0
  26. data/app/views/layouts/rocket_job_mission_control/partials/_sidebar.html.erb +12 -0
  27. data/app/views/rocket_job_mission_control/active_workers/index.html.erb +40 -0
  28. data/app/views/rocket_job_mission_control/dirmon_entries/_form.html.erb +60 -0
  29. data/app/views/rocket_job_mission_control/dirmon_entries/_sidebar.html.erb +38 -0
  30. data/app/views/rocket_job_mission_control/dirmon_entries/_status.html.erb +17 -0
  31. data/app/views/rocket_job_mission_control/dirmon_entries/edit.html.erb +4 -0
  32. data/app/views/rocket_job_mission_control/dirmon_entries/index.html.erb +33 -0
  33. data/app/views/rocket_job_mission_control/dirmon_entries/new.html.erb +8 -0
  34. data/app/views/rocket_job_mission_control/dirmon_entries/show.html.erb +29 -0
  35. data/app/views/rocket_job_mission_control/jobs/_pagination.html.erb +26 -0
  36. data/app/views/rocket_job_mission_control/jobs/_sidebar.html.erb +32 -0
  37. data/app/views/rocket_job_mission_control/jobs/_status.html.erb +42 -0
  38. data/app/views/rocket_job_mission_control/jobs/edit.html.erb +32 -0
  39. data/app/views/rocket_job_mission_control/jobs/exception.html.erb +19 -0
  40. data/app/views/rocket_job_mission_control/jobs/exceptions.html.erb +40 -0
  41. data/app/views/rocket_job_mission_control/jobs/index.html.erb +33 -0
  42. data/app/views/rocket_job_mission_control/jobs/show.html.erb +68 -0
  43. data/app/views/rocket_job_mission_control/servers/_sidebar.html.erb +31 -0
  44. data/app/views/rocket_job_mission_control/servers/index.html.erb +56 -0
  45. data/config/locales/en.yml +3 -10
  46. data/config/routes.rb +20 -17
  47. data/lib/rocket_job_mission_control/engine.rb +10 -0
  48. data/lib/rocket_job_mission_control/version.rb +1 -1
  49. data/test/compare_hashes.rb +17 -0
  50. data/test/controllers/rocket_job_mission_control/application_controller_test.rb +49 -0
  51. data/test/controllers/rocket_job_mission_control/dirmon_entries_controller_test.rb +417 -0
  52. data/test/controllers/rocket_job_mission_control/jobs_controller_test.rb +363 -0
  53. data/test/controllers/rocket_job_mission_control/servers_controller_test.rb +251 -0
  54. data/test/helpers/rocket_job_mission_control/application_helper_test.rb +54 -0
  55. data/test/helpers/rocket_job_mission_control/jobs_helper_test.rb +85 -0
  56. data/test/helpers/rocket_job_mission_control/pagination_helper_test.rb +23 -0
  57. data/test/helpers/rocket_job_mission_control/servers_helper_test.rb +64 -0
  58. data/test/helpers/rocket_job_mission_control/slices_helper_test.rb +30 -0
  59. data/test/models/rocket_job_mission_control/job_sanitizer_test.rb +92 -0
  60. data/test/models/rocket_job_mission_control/query_test.rb +136 -0
  61. data/test/test_helper.rb +23 -0
  62. metadata +75 -175
  63. data/app/assets/javascripts/rocket_job_mission_control/base.js.coffee +0 -11
  64. data/app/assets/javascripts/rocket_job_mission_control/datatable.js.coffee +0 -33
  65. data/app/assets/javascripts/rocket_job_mission_control/dirmon_entries.js.coffee +0 -13
  66. data/app/assets/javascripts/rocket_job_mission_control/selectize.js.coffee +0 -5
  67. data/app/assets/stylesheets/rocket_job_mission_control/jquery.bootstrap-touchspin.scss +0 -45
  68. data/app/controllers/rocket_job_mission_control/dirmon_entries/index_filters_controller.rb +0 -45
  69. data/app/controllers/rocket_job_mission_control/jobs/failures_controller.rb +0 -30
  70. data/app/controllers/rocket_job_mission_control/jobs/index_filters_controller.rb +0 -90
  71. data/app/controllers/rocket_job_mission_control/servers/index_filters_controller.rb +0 -49
  72. data/app/datatables/rocket_job_mission_control/completed_jobs_datatable.rb +0 -27
  73. data/app/datatables/rocket_job_mission_control/interrupted_jobs_datatable.rb +0 -26
  74. data/app/datatables/rocket_job_mission_control/queued_jobs_datatable.rb +0 -23
  75. data/app/datatables/rocket_job_mission_control/running_jobs_datatable.rb +0 -47
  76. data/app/datatables/rocket_job_mission_control/scheduled_jobs_datatable.rb +0 -31
  77. data/app/models/job_failures.rb +0 -20
  78. data/app/models/job_sanitizer.rb +0 -17
  79. data/app/views/layouts/rocket_job_mission_control/application.html.haml +0 -45
  80. data/app/views/layouts/rocket_job_mission_control/partials/_header.html.haml +0 -32
  81. data/app/views/layouts/rocket_job_mission_control/partials/_sidebar.html.haml +0 -11
  82. data/app/views/rocket_job_mission_control/active_workers/index.html.haml +0 -24
  83. data/app/views/rocket_job_mission_control/dirmon_entries/_form.html.haml +0 -37
  84. data/app/views/rocket_job_mission_control/dirmon_entries/_properties.html.haml +0 -30
  85. data/app/views/rocket_job_mission_control/dirmon_entries/_sidebar.html.haml +0 -27
  86. data/app/views/rocket_job_mission_control/dirmon_entries/_status.html.haml +0 -23
  87. data/app/views/rocket_job_mission_control/dirmon_entries/edit.html.haml +0 -4
  88. data/app/views/rocket_job_mission_control/dirmon_entries/index.html.haml +0 -18
  89. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/disabled.html.haml +0 -17
  90. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/enabled.html.haml +0 -17
  91. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/failed.html.haml +0 -17
  92. data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/pending.html.haml +0 -17
  93. data/app/views/rocket_job_mission_control/dirmon_entries/new.html.haml +0 -6
  94. data/app/views/rocket_job_mission_control/dirmon_entries/show.html.haml +0 -23
  95. data/app/views/rocket_job_mission_control/jobs/_sidebar.html.haml +0 -28
  96. data/app/views/rocket_job_mission_control/jobs/_status.html.haml +0 -45
  97. data/app/views/rocket_job_mission_control/jobs/edit.html.haml +0 -34
  98. data/app/views/rocket_job_mission_control/jobs/exceptions.html.haml +0 -29
  99. data/app/views/rocket_job_mission_control/jobs/failures/_pagination.html.haml +0 -16
  100. data/app/views/rocket_job_mission_control/jobs/failures/index.html.haml +0 -32
  101. data/app/views/rocket_job_mission_control/jobs/index.html.haml +0 -25
  102. data/app/views/rocket_job_mission_control/jobs/index_filters/aborted.html.haml +0 -23
  103. data/app/views/rocket_job_mission_control/jobs/index_filters/completed.html.haml +0 -24
  104. data/app/views/rocket_job_mission_control/jobs/index_filters/failed.html.haml +0 -23
  105. data/app/views/rocket_job_mission_control/jobs/index_filters/paused.html.haml +0 -23
  106. data/app/views/rocket_job_mission_control/jobs/index_filters/queued.html.haml +0 -24
  107. data/app/views/rocket_job_mission_control/jobs/index_filters/running.html.haml +0 -25
  108. data/app/views/rocket_job_mission_control/jobs/index_filters/scheduled.html.haml +0 -24
  109. data/app/views/rocket_job_mission_control/jobs/show.html.haml +0 -51
  110. data/app/views/rocket_job_mission_control/servers/_actions.html.haml +0 -9
  111. data/app/views/rocket_job_mission_control/servers/_sidebar.html.haml +0 -20
  112. data/app/views/rocket_job_mission_control/servers/index.html.haml +0 -37
  113. data/app/views/rocket_job_mission_control/servers/index_filters/paused.html.haml +0 -37
  114. data/app/views/rocket_job_mission_control/servers/index_filters/running.html.haml +0 -37
  115. data/app/views/rocket_job_mission_control/servers/index_filters/starting.html.haml +0 -37
  116. data/app/views/rocket_job_mission_control/servers/index_filters/stopping.html.haml +0 -37
  117. data/spec/controllers/application_controller_spec.rb +0 -47
  118. data/spec/controllers/dirmon_entries/index_filters_controller_spec.rb +0 -77
  119. data/spec/controllers/dirmon_entries_controller_spec.rb +0 -383
  120. data/spec/controllers/jobs/failures_controller_spec.rb +0 -82
  121. data/spec/controllers/jobs/index_filters_controller_spec.rb +0 -66
  122. data/spec/controllers/jobs_controller_spec.rb +0 -172
  123. data/spec/controllers/workers/index_filters_controller_spec.rb +0 -59
  124. data/spec/controllers/workers_controller_spec.rb +0 -125
  125. data/spec/dummy/Rakefile +0 -7
  126. data/spec/dummy/config.ru +0 -4
  127. data/spec/dummy/config/application.rb +0 -26
  128. data/spec/dummy/config/boot.rb +0 -5
  129. data/spec/dummy/config/database.yml +0 -25
  130. data/spec/dummy/config/environment.rb +0 -5
  131. data/spec/dummy/config/environments/test.rb +0 -37
  132. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  133. data/spec/dummy/config/initializers/session_store.rb +0 -3
  134. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  135. data/spec/dummy/config/mongoid.yml +0 -88
  136. data/spec/dummy/config/routes.rb +0 -3
  137. data/spec/dummy/config/secrets.yml +0 -22
  138. data/spec/dummy/config/symmetric-encryption.yml +0 -8
  139. data/spec/dummy/db/test.sqlite3 +0 -0
  140. data/spec/dummy/log/development.log +0 -0
  141. data/spec/dummy/log/test.log +0 -118933
  142. data/spec/helpers/application_helper_spec.rb +0 -58
  143. data/spec/helpers/jobs_helper_spec.rb +0 -35
  144. data/spec/helpers/pagination_helper_spec.rb +0 -21
  145. data/spec/helpers/servers_helper_spec.rb +0 -16
  146. data/spec/helpers/slices_helper_spec.rb +0 -33
  147. data/spec/models/job_failures_spec.rb +0 -14
  148. data/spec/models/job_sanitizer_spec.rb +0 -16
  149. data/spec/rails_helper.rb +0 -47
  150. data/spec/spec_helper.rb +0 -84
  151. data/vendor/assets/javascripts/jquery.bootstrap-touchspin.js +0 -686
  152. data/vendor/assets/javascripts/prism.js +0 -6
  153. data/vendor/assets/stylesheets/jquery.bootstrap-touchspin.css +0 -45
  154. data/vendor/assets/stylesheets/prism.scss +0 -160
@@ -0,0 +1,56 @@
1
+ <div id='servers'>
2
+ <div class='server-list'>
3
+ <div class='list'>
4
+ <div class='row'>
5
+ <div class='col-md-6'>
6
+ <h2><%= @description %> Servers</h2>
7
+ </div>
8
+ <div class='col-md-6'>
9
+ <div class='col-sm-10'>
10
+ <div class='server-collection-actions'>
11
+ <ol>
12
+ <div class='btn-group'>
13
+ <% Array(@actions).each do |action| %>
14
+ <%= link_to(
15
+ "#{action.to_s.humanize.capitalize}",
16
+ rocket_job_mission_control.update_all_servers_path(server_action: action),
17
+ method: :patch,
18
+ data: {confirm: t(:confirm, scope: [:server, :update_all], action: action.to_s.singularize.humanize.downcase)},
19
+ class: 'btn btn-default')
20
+ %>
21
+ <% end %>
22
+ </div>
23
+ </ol>
24
+ </div>
25
+ </div>
26
+ <div class='col-sm-2 pull-right'>
27
+ <div class='btn btn-default pull-right dt-reload' data-behavior='reload'>
28
+ <i class='fa fa-refresh'></i>
29
+ </div>
30
+ </div>
31
+ </div>
32
+ </div>
33
+ <table class='table datatable servers-datatable' data-source='<%= @data_table_url %>' style='width: 100%'>
34
+ <thead>
35
+ <tr>
36
+ <th>Hostname : PID</th>
37
+ <th>Workers (Current/Max)</th>
38
+ <th>Started</th>
39
+ <th>Heartbeat</th>
40
+ <th>Actions</th>
41
+ </tr>
42
+ </thead>
43
+ <tbody></tbody>
44
+ </table>
45
+ </div>
46
+ </div>
47
+ </div>
48
+
49
+ <script>
50
+ jQuery(function () {
51
+ new RjmcDatatable(
52
+ $('.servers-datatable'),
53
+ [{data: '0'}, {data: '1'}, {data: '2'}, {data: '3'}, {data: '4', orderable: false}]
54
+ );
55
+ });
56
+ </script>
@@ -37,20 +37,18 @@ en:
37
37
  one: "1 year" # default was: "almost 1 year"
38
38
  other: "%{count} years" # default was: "almost %{count} years"
39
39
  server:
40
+ find:
41
+ failure: "Could not find server with id: %{id}!"
40
42
  stop:
41
- success: "Server successfully stopped."
42
43
  failure: "Error attempting to stop server."
43
44
  destroy:
44
- success: "Server successfully destroyed."
45
+ success: "Server successfully destroyed. All jobs running on this server have been re-queued for processing on other servers."
45
46
  failure: "Error attempting to destroy server."
46
47
  pause:
47
- success: "Server successfully paused."
48
48
  failure: "Error attempting to pause server."
49
49
  resume:
50
- success: "Server successfully resumed."
51
50
  failure: "Error attempting to resume server."
52
51
  update_all:
53
- success: "Servers have been %{server_action}."
54
52
  invalid: "Action not allowed."
55
53
  confirm: "Are you sure you want to %{action} servers?"
56
54
  job:
@@ -65,17 +63,12 @@ en:
65
63
  find:
66
64
  failure: "Could not find entry with id: %{id}!"
67
65
  create:
68
- success: "Dirmon successfully created."
69
66
  failure: "Error attempting to create."
70
67
  destroy:
71
- success: "Dirmon successfully destroyed."
72
68
  failure: "Error attempting to destroy Dirmon."
73
69
  enable:
74
- success: "Dirmon successfully enabled."
75
70
  failure: "Error attempting to enable Dirmon."
76
71
  disable:
77
- success: "Dirmon successfully disabled."
78
72
  failure: "Error attempting to disable Dirmon."
79
73
  update:
80
- success: "Dirmon has been updated."
81
74
  invalid: "Error attempting to update Dirmon."
@@ -2,13 +2,13 @@ RocketJobMissionControl::Engine.routes.draw do
2
2
 
3
3
  resources :jobs, only: [:index, :show, :update, :destroy, :edit] do
4
4
  collection do
5
- get :running, to: 'jobs/index_filters#running'
6
- get :scheduled, to: 'jobs/index_filters#scheduled'
7
- get :completed, to: 'jobs/index_filters#completed'
8
- get :queued, to: 'jobs/index_filters#queued'
9
- get :paused, to: 'jobs/index_filters#paused'
10
- get :failed, to: 'jobs/index_filters#failed'
11
- get :aborted, to: 'jobs/index_filters#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'
12
12
  end
13
13
 
14
14
  member do
@@ -19,18 +19,19 @@ RocketJobMissionControl::Engine.routes.draw do
19
19
  patch :retry
20
20
  patch :run_now
21
21
  get :exceptions
22
+ get :exception
22
23
  end
23
- resources :failures, controller: 'jobs/failures', only: :index
24
24
  end
25
25
 
26
26
  resources :active_workers, only: :index
27
27
 
28
28
  resources :servers, only: [:index, :destroy] do
29
29
  collection do
30
- get :starting, to: 'servers/index_filters#starting'
31
- get :running, to: 'servers/index_filters#running'
32
- get :paused, to: 'servers/index_filters#paused'
33
- get :stopping, to: 'servers/index_filters#stopping'
30
+ get :starting, to: 'servers#starting'
31
+ get :running, to: 'servers#running'
32
+ get :paused, to: 'servers#paused'
33
+ get :stopping, to: 'servers#stopping'
34
+ get :zombie, to: 'servers#zombie'
34
35
  end
35
36
 
36
37
  member do
@@ -45,10 +46,10 @@ RocketJobMissionControl::Engine.routes.draw do
45
46
 
46
47
  resources :dirmon_entries do
47
48
  collection do
48
- get :pending, to: 'dirmon_entries/index_filters#pending'
49
- get :enabled, to: 'dirmon_entries/index_filters#enabled'
50
- get :failed, to: 'dirmon_entries/index_filters#failed'
51
- get :disabled, to: 'dirmon_entries/index_filters#disabled'
49
+ get :pending, to: 'dirmon_entries#pending'
50
+ get :enabled, to: 'dirmon_entries#enabled'
51
+ get :failed, to: 'dirmon_entries#failed'
52
+ get :disabled, to: 'dirmon_entries#disabled'
52
53
  end
53
54
 
54
55
  member do
@@ -57,5 +58,7 @@ RocketJobMissionControl::Engine.routes.draw do
57
58
  end
58
59
  end
59
60
 
60
- root to: "jobs/index_filters#running"
61
+ get 'rocket_job_mission_control/test' => 'test#index' if Rails.env.test?
62
+
63
+ root to: "jobs#running"
61
64
  end
@@ -2,6 +2,16 @@ module RocketJobMissionControl
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace RocketJobMissionControl
4
4
 
5
+ require 'rocketjob'
6
+ require 'jquery-rails'
7
+ require 'bootstrap-sass'
8
+ require 'sass-rails'
9
+ require 'jquery-datatables-rails'
10
+ begin
11
+ require 'rocketjob_pro'
12
+ rescue LoadError
13
+ end
14
+
5
15
  config.to_prepare do
6
16
  Rails.application.config.assets.precompile += %w(
7
17
  rocket_job_mission_control/rocket-icon-64x64.png
@@ -1,3 +1,3 @@
1
1
  module RocketJobMissionControl
2
- VERSION = '3.0.0.rc1'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -0,0 +1,17 @@
1
+ def compare_array_of_hashes(expected, actual)
2
+ expected.each_with_index do |expected_hash, index|
3
+ compare_hash(expected_hash, actual[index])
4
+ end
5
+ end
6
+
7
+ def compare_hash(expected_hash, actual_hash)
8
+ expected_hash.each_pair do |key, expected|
9
+ actual = actual_hash[key]
10
+ if expected.is_a?(Regexp)
11
+ assert_match expected, actual, "#{key} does not match. Expected #{expected.inspect}. Actual #{actual.inspect}"
12
+ else
13
+ assert_equal expected, actual, "#{key} not equal. Expected #{expected.inspect}. Actual #{actual.inspect}"
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,49 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module RocketJobMissionControl
4
+ class TestController < ApplicationController
5
+ def index
6
+ @time_zone = Time.zone
7
+
8
+ render text: 'Time Zoned'
9
+ end
10
+ end
11
+
12
+ class ApplicationControllerTest < ActionController::TestCase
13
+ describe TestController do
14
+ describe '#with_time_zone' do
15
+ let(:session_params) { {} }
16
+ let(:expected_time_zone) { 'UTC' }
17
+
18
+ before do
19
+ get :index, {}, session_params
20
+ end
21
+
22
+ describe 'with a session present' do
23
+ describe 'that contains a time zone' do
24
+ let(:expected_time_zone) { 'America/Los_Angeles' }
25
+ let(:session_params) { {'time_zone' => expected_time_zone} }
26
+
27
+ it 'sets the time zone correctly' do
28
+ assert_equal expected_time_zone, assigns(:time_zone).name
29
+ end
30
+ end
31
+
32
+ describe 'that does not contain a time zone' do
33
+ let(:session_params) { {'user_id' => '42'} }
34
+
35
+ it 'sets the time zone correctly' do
36
+ assert_equal expected_time_zone, assigns(:time_zone).name
37
+ end
38
+ end
39
+ end
40
+
41
+ describe 'with no session present' do
42
+ it 'sets the time zone correctly' do
43
+ assert_equal expected_time_zone, assigns(:time_zone).name
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,417 @@
1
+ require_relative '../../test_helper'
2
+ require_relative '../../compare_hashes'
3
+
4
+ module RocketJobMissionControl
5
+ class DirmonEntriesControllerTest < ActionController::TestCase
6
+
7
+ describe DirmonEntriesController do
8
+ before do
9
+ RocketJob::DirmonEntry.delete_all
10
+ end
11
+
12
+ let :job_class_name do
13
+ 'RocketJob::Jobs::SimpleJob'
14
+ end
15
+
16
+ let :existing_dirmon_entry do
17
+ RocketJob::DirmonEntry.create!(
18
+ name: 'Test',
19
+ job_class_name: job_class_name,
20
+ pattern: 'the_path'
21
+ )
22
+ end
23
+
24
+ dirmon_entry_states = RocketJob::DirmonEntry.aasm.states.collect(&:name)
25
+
26
+ let :one_dirmon_entry_for_every_state do
27
+ dirmon_entry_states.collect do |state|
28
+ RocketJob::DirmonEntry.create!(
29
+ name: 'Test',
30
+ job_class_name: job_class_name,
31
+ pattern: 'the_path',
32
+ state: state
33
+ )
34
+ end
35
+ end
36
+
37
+ describe 'PATCH #enable' do
38
+ describe 'when transition is allowed' do
39
+ before do
40
+ patch :enable, id: existing_dirmon_entry.id
41
+ end
42
+
43
+ it do
44
+ assert_redirected_to dirmon_entry_path(existing_dirmon_entry)
45
+ end
46
+
47
+ it 'changes the state to enabled' do
48
+ assert existing_dirmon_entry.reload.enabled?
49
+ end
50
+ end
51
+
52
+ describe 'when transition is not allowed' do
53
+ before do
54
+ existing_dirmon_entry.enable!
55
+ patch :enable, id: existing_dirmon_entry.id
56
+ end
57
+
58
+ it 'succeeds' do
59
+ assert_response :success
60
+ end
61
+
62
+ it 'alerts the user' do
63
+ assert_equal I18n.t(:failure, scope: [:dirmon_entry, :enable]), flash[:alert]
64
+ end
65
+ end
66
+ end
67
+
68
+ describe 'PATCH #disable' do
69
+ describe 'when transition is allowed' do
70
+ before do
71
+ existing_dirmon_entry.enable!
72
+ patch :disable, id: existing_dirmon_entry.id
73
+ end
74
+
75
+ it do
76
+ assert_redirected_to dirmon_entry_path(existing_dirmon_entry)
77
+ end
78
+
79
+ it 'changes the state to disabled' do
80
+ assert existing_dirmon_entry.reload.disabled?
81
+ end
82
+ end
83
+
84
+ describe 'when transition is not allowed' do
85
+ before do
86
+ patch :disable, id: existing_dirmon_entry.id
87
+ end
88
+
89
+ it 'succeeds' do
90
+ assert_response :success
91
+ end
92
+
93
+ it 'alerts the user' do
94
+ assert_equal I18n.t(:failure, scope: [:dirmon_entry, :disable]), flash[:alert]
95
+ end
96
+ end
97
+ end
98
+
99
+ describe 'GET #new' do
100
+ let(:entry_params) { {} }
101
+
102
+ before do
103
+ get :new, entry_params
104
+ end
105
+
106
+ it 'succeeds' do
107
+ assert_response :success
108
+ end
109
+
110
+ it 'assigns a new entry' do
111
+ assert assigns(:dirmon_entry).present?
112
+ refute assigns(:dirmon_entry).persisted?
113
+ end
114
+
115
+ describe 'with form params' do
116
+ let(:entry_params) { {rocket_job_dirmon_entry: {name: 'new entry'}} }
117
+
118
+ it 'succeeds' do
119
+ assert_response :success
120
+ end
121
+
122
+ it 'assigns the params to new entry' do
123
+ assert_equal 'new entry', assigns(:dirmon_entry).name
124
+ end
125
+
126
+ describe 'with a valid job_class_name' do
127
+ let(:entry_params) { {rocket_job_dirmon_entry: {job_class_name: 'NoParamsJob'}} }
128
+
129
+ it 'succeeds' do
130
+ assert_response :success
131
+ end
132
+
133
+ it 'assigns the job class' do
134
+ assert_equal 'NoParamsJob', assigns(:dirmon_entry).job_class_name
135
+ end
136
+ end
137
+
138
+ describe 'with an invalid job_class_name' do
139
+ let(:entry_params) { {rocket_job_dirmon_entry: {job_class_name: 'BadJob'}} }
140
+
141
+ it 'succeeds' do
142
+ assert_response :success
143
+ end
144
+
145
+ it 'adds an error' do
146
+ assert assigns(:dirmon_entry).errors[:job_class_name].present?
147
+ end
148
+ end
149
+ end
150
+
151
+ end
152
+
153
+ describe 'PATCH #update' do
154
+ describe 'with valid parameters' do
155
+ before do
156
+ patch :update, id: existing_dirmon_entry.id, rocket_job_dirmon_entry: {pattern: 'the_path2', job_class_name: job_class_name}
157
+ end
158
+
159
+ it 'redirects to the updated entry' do
160
+ assert_redirected_to dirmon_entry_path(existing_dirmon_entry)
161
+ end
162
+
163
+ it 'updates the entry' do
164
+ #follow_redirect!
165
+ #assert_equal 'the_path2', existing_dirmon_entry.reload.pattern
166
+ end
167
+ end
168
+
169
+ describe 'with invalid parameters' do
170
+ before do
171
+ patch :update, id: existing_dirmon_entry.id, rocket_job_dirmon_entry: {job_class_name: 'FakeAndBadJob'}
172
+ end
173
+
174
+ it 'renders the edit template' do
175
+ assert_redirected_to dirmon_entry_path(existing_dirmon_entry)
176
+ end
177
+
178
+ it 'alerts the user' do
179
+ #follow_redirect!
180
+ #assert_select 'div.message', "job_class_name: #{I18n.t(:failure, scope: [:dirmon_entry, :disable])}"
181
+ end
182
+ end
183
+ end
184
+
185
+ describe 'POST #create' do
186
+ describe 'with valid parameters' do
187
+ let(:dirmon_params) do
188
+ {
189
+ name: 'Test',
190
+ pattern: '/files/*',
191
+ job_class_name: job_class_name,
192
+ properties: {description: '', priority: '42'}
193
+ }
194
+ end
195
+
196
+ before do
197
+ post :create, rocket_job_dirmon_entry: dirmon_params
198
+ end
199
+
200
+ it 'creates the entry' do
201
+ assert assigns(:dirmon_entry).persisted?
202
+ end
203
+
204
+ it 'has no errors' do
205
+ assert assigns(:dirmon_entry).errors.messages.empty?
206
+ end
207
+
208
+ it 'redirects to created entry' do
209
+ assert_redirected_to dirmon_entry_path(assigns(:dirmon_entry))
210
+ end
211
+
212
+ it 'does not save blank properties' do
213
+ assert_nil assigns(:dirmon_entry).properties[:description]
214
+ end
215
+
216
+ it 'saves properties' do
217
+ assert_equal '42', assigns(:dirmon_entry).properties[:priority]
218
+ end
219
+
220
+ [:name, :pattern, :job_class_name].each do |attribute|
221
+ it "assigns the correct value for #{attribute}" do
222
+ assert_equal dirmon_params[attribute], assigns(:dirmon_entry)[attribute]
223
+ end
224
+ end
225
+ end
226
+
227
+ describe 'with invalid parameters' do
228
+ let(:dirmon_params) do
229
+ {
230
+ name: 'Test',
231
+ job_class_name: 'FakeAndBadJob'
232
+ }
233
+ end
234
+
235
+ before do
236
+ post :create, rocket_job_dirmon_entry: dirmon_params
237
+ end
238
+
239
+ describe 'on model attributes' do
240
+ it 'renders the new template' do
241
+ assert_response :success
242
+ assert_template :new
243
+ end
244
+
245
+ it 'has errors on the entry' do
246
+ refute assigns(:dirmon_entry).valid?
247
+ end
248
+ end
249
+ end
250
+ end
251
+
252
+ describe 'GET #edit' do
253
+ before do
254
+ get :edit, id: existing_dirmon_entry.id
255
+ end
256
+
257
+ it 'succeeds' do
258
+ assert_response :success
259
+ end
260
+
261
+ it 'assigns the entry' do
262
+ assert_equal existing_dirmon_entry, assigns(:dirmon_entry)
263
+ end
264
+ end
265
+
266
+ describe 'GET #show' do
267
+ describe 'with an invalid id' do
268
+ before do
269
+ get :show, id: 42
270
+ end
271
+
272
+ it 'redirects' do
273
+ assert_redirected_to dirmon_entries_path
274
+ end
275
+
276
+ it 'adds a flash alert message' do
277
+ assert_equal I18n.t(:failure, scope: [:dirmon_entry, :find], id: 42), flash[:alert]
278
+ end
279
+ end
280
+
281
+ describe 'with a valid id' do
282
+ before do
283
+ get :show, id: existing_dirmon_entry.id
284
+ end
285
+
286
+ it 'succeeds' do
287
+ assert_response :success
288
+ end
289
+
290
+ it 'assigns the entry' do
291
+ assert assigns(:dirmon_entry).present?
292
+ end
293
+ end
294
+ end
295
+
296
+ describe 'DELETE #destroy' do
297
+ describe 'with a valid id' do
298
+ before { delete :destroy, id: existing_dirmon_entry.id }
299
+
300
+ it 'redirects to index' do
301
+ assert_redirected_to dirmon_entries_path
302
+ end
303
+
304
+ it 'deletes the entry' do
305
+ refute RocketJob::DirmonEntry.where(id: existing_dirmon_entry.id).exists?
306
+ end
307
+ end
308
+ end
309
+
310
+ ([:index] + dirmon_entry_states).each do |state|
311
+ describe "GET ##{state}" do
312
+ describe 'html' do
313
+ describe "with no #{state} entries" do
314
+ before do
315
+ get state
316
+ end
317
+
318
+ it 'succeeds' do
319
+ assert_response :success
320
+ end
321
+
322
+ it 'renders template' do
323
+ assert_template :index
324
+ end
325
+ end
326
+
327
+ describe "with #{state} entries" do
328
+ before do
329
+ one_dirmon_entry_for_every_state
330
+ get state
331
+ end
332
+
333
+ it 'succeeds' do
334
+ assert_response :success
335
+ end
336
+
337
+ it 'renders template' do
338
+ assert_template :index
339
+ end
340
+ end
341
+ end
342
+
343
+ describe 'json' do
344
+ describe "with #{state} entries" do
345
+ before do
346
+ get state, format: :json
347
+ end
348
+
349
+ it 'succeeds' do
350
+ assert_response :success
351
+ json = JSON.parse(response.body)
352
+ expected = {
353
+ "data" => [],
354
+ "draw" => 0,
355
+ "recordsFiltered" => 0,
356
+ "recordsTotal" => 0
357
+ }
358
+ assert_equal expected, json
359
+ end
360
+ end
361
+
362
+ describe "with #{state} entries" do
363
+ before do
364
+ one_dirmon_entry_for_every_state
365
+ get state, format: :json
366
+ end
367
+
368
+ it 'succeeds' do
369
+ assert_response :success
370
+ json = JSON.parse(response.body)
371
+ expected_data = {
372
+ pending: {
373
+ "0" => " <a href=\"/dirmon_entries/#{RocketJob::DirmonEntry.pending.first.id}\">\n <i class=\"fa fa-inbox pending\" style=\"font-size: 75%\" title=\"pending\"></i>\n Test\n </a>\n",
374
+ "1" => "RocketJob::Jobs::SimpleJob",
375
+ "2" => "the_path",
376
+ "DT_RowClass" => "card callout callout-pending"
377
+ },
378
+ enabled: {
379
+ "0" => " <a href=\"/dirmon_entries/#{RocketJob::DirmonEntry.enabled.first.id}\">\n <i class=\"fa fa-check enabled\" style=\"font-size: 75%\" title=\"enabled\"></i>\n Test\n </a>\n",
380
+ "1" => "RocketJob::Jobs::SimpleJob",
381
+ "2" => "the_path",
382
+ "DT_RowClass" => "card callout callout-enabled"
383
+ },
384
+ failed: {
385
+ "0" => " <a href=\"/dirmon_entries/#{RocketJob::DirmonEntry.failed.first.id}\">\n <i class=\"fa fa-exclamation-triangle failed\" style=\"font-size: 75%\" title=\"failed\"></i>\n Test\n </a>\n",
386
+ "1" => "RocketJob::Jobs::SimpleJob",
387
+ "2" => "the_path",
388
+ "DT_RowClass" => "card callout callout-failed"
389
+ },
390
+ disabled: {
391
+ "0" => " <a href=\"/dirmon_entries/#{RocketJob::DirmonEntry.disabled.first.id}\">\n <i class=\"fa fa-stop disabled\" style=\"font-size: 75%\" title=\"disabled\"></i>\n Test\n </a>\n",
392
+ "1" => "RocketJob::Jobs::SimpleJob",
393
+ "2" => "the_path",
394
+ "DT_RowClass" => "card callout callout-disabled"
395
+ }
396
+ }
397
+
398
+ if state == :index
399
+ assert_equal 0, json['draw']
400
+ assert_equal 4, json['recordsTotal']
401
+ assert_equal 4, json['recordsFiltered']
402
+ assert_equal [expected_data[:pending], expected_data[:enabled], expected_data[:failed], expected_data[:disabled]], json['data']
403
+ else
404
+ assert_equal 0, json['draw']
405
+ assert_equal 1, json['recordsTotal']
406
+ assert_equal 1, json['recordsFiltered']
407
+ assert_equal [expected_data[state]], json['data']
408
+ end
409
+ end
410
+ end
411
+ end
412
+
413
+ end
414
+ end
415
+ end
416
+ end
417
+ end