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.
- checksums.yaml +4 -4
- data/Rakefile +10 -6
- data/app/assets/javascripts/rocket_job_mission_control/application.js +4 -3
- data/app/assets/javascripts/rocket_job_mission_control/base.js +12 -0
- data/app/assets/javascripts/rocket_job_mission_control/datatable.js +40 -0
- data/app/assets/javascripts/rocket_job_mission_control/dirmon_entries.js +16 -0
- data/app/assets/javascripts/rocket_job_mission_control/selectize.js +6 -0
- data/app/controllers/rocket_job_mission_control/active_workers_controller.rb +16 -5
- data/app/controllers/rocket_job_mission_control/application_controller.rb +2 -0
- data/app/controllers/rocket_job_mission_control/dirmon_entries_controller.rb +47 -67
- data/app/controllers/rocket_job_mission_control/jobs_controller.rb +113 -19
- data/app/controllers/rocket_job_mission_control/servers_controller.rb +71 -28
- data/app/datatables/rocket_job_mission_control/abstract_datatable.rb +3 -3
- data/app/datatables/rocket_job_mission_control/active_workers_datatable.rb +8 -14
- data/app/datatables/rocket_job_mission_control/dirmon_entries_datatable.rb +7 -15
- data/app/datatables/rocket_job_mission_control/jobs_datatable.rb +128 -13
- data/app/datatables/rocket_job_mission_control/servers_datatable.rb +13 -15
- data/app/helpers/rocket_job_mission_control/application_helper.rb +58 -0
- data/app/helpers/rocket_job_mission_control/jobs_helper.rb +15 -7
- data/app/helpers/rocket_job_mission_control/servers_helper.rb +1 -1
- data/app/models/rocket_job_mission_control/job_sanitizer.rb +47 -0
- data/app/models/rocket_job_mission_control/query.rb +24 -18
- data/app/views/layouts/rocket_job_mission_control/application.html.erb +43 -0
- data/app/views/layouts/rocket_job_mission_control/partials/_flash.html.erb +20 -0
- data/app/views/layouts/rocket_job_mission_control/partials/_header.html.erb +45 -0
- data/app/views/layouts/rocket_job_mission_control/partials/_sidebar.html.erb +12 -0
- data/app/views/rocket_job_mission_control/active_workers/index.html.erb +40 -0
- data/app/views/rocket_job_mission_control/dirmon_entries/_form.html.erb +60 -0
- data/app/views/rocket_job_mission_control/dirmon_entries/_sidebar.html.erb +38 -0
- data/app/views/rocket_job_mission_control/dirmon_entries/_status.html.erb +17 -0
- data/app/views/rocket_job_mission_control/dirmon_entries/edit.html.erb +4 -0
- data/app/views/rocket_job_mission_control/dirmon_entries/index.html.erb +33 -0
- data/app/views/rocket_job_mission_control/dirmon_entries/new.html.erb +8 -0
- data/app/views/rocket_job_mission_control/dirmon_entries/show.html.erb +29 -0
- data/app/views/rocket_job_mission_control/jobs/_pagination.html.erb +26 -0
- data/app/views/rocket_job_mission_control/jobs/_sidebar.html.erb +32 -0
- data/app/views/rocket_job_mission_control/jobs/_status.html.erb +42 -0
- data/app/views/rocket_job_mission_control/jobs/edit.html.erb +32 -0
- data/app/views/rocket_job_mission_control/jobs/exception.html.erb +19 -0
- data/app/views/rocket_job_mission_control/jobs/exceptions.html.erb +40 -0
- data/app/views/rocket_job_mission_control/jobs/index.html.erb +33 -0
- data/app/views/rocket_job_mission_control/jobs/show.html.erb +68 -0
- data/app/views/rocket_job_mission_control/servers/_sidebar.html.erb +31 -0
- data/app/views/rocket_job_mission_control/servers/index.html.erb +56 -0
- data/config/locales/en.yml +3 -10
- data/config/routes.rb +20 -17
- data/lib/rocket_job_mission_control/engine.rb +10 -0
- data/lib/rocket_job_mission_control/version.rb +1 -1
- data/test/compare_hashes.rb +17 -0
- data/test/controllers/rocket_job_mission_control/application_controller_test.rb +49 -0
- data/test/controllers/rocket_job_mission_control/dirmon_entries_controller_test.rb +417 -0
- data/test/controllers/rocket_job_mission_control/jobs_controller_test.rb +363 -0
- data/test/controllers/rocket_job_mission_control/servers_controller_test.rb +251 -0
- data/test/helpers/rocket_job_mission_control/application_helper_test.rb +54 -0
- data/test/helpers/rocket_job_mission_control/jobs_helper_test.rb +85 -0
- data/test/helpers/rocket_job_mission_control/pagination_helper_test.rb +23 -0
- data/test/helpers/rocket_job_mission_control/servers_helper_test.rb +64 -0
- data/test/helpers/rocket_job_mission_control/slices_helper_test.rb +30 -0
- data/test/models/rocket_job_mission_control/job_sanitizer_test.rb +92 -0
- data/test/models/rocket_job_mission_control/query_test.rb +136 -0
- data/test/test_helper.rb +23 -0
- metadata +75 -175
- data/app/assets/javascripts/rocket_job_mission_control/base.js.coffee +0 -11
- data/app/assets/javascripts/rocket_job_mission_control/datatable.js.coffee +0 -33
- data/app/assets/javascripts/rocket_job_mission_control/dirmon_entries.js.coffee +0 -13
- data/app/assets/javascripts/rocket_job_mission_control/selectize.js.coffee +0 -5
- data/app/assets/stylesheets/rocket_job_mission_control/jquery.bootstrap-touchspin.scss +0 -45
- data/app/controllers/rocket_job_mission_control/dirmon_entries/index_filters_controller.rb +0 -45
- data/app/controllers/rocket_job_mission_control/jobs/failures_controller.rb +0 -30
- data/app/controllers/rocket_job_mission_control/jobs/index_filters_controller.rb +0 -90
- data/app/controllers/rocket_job_mission_control/servers/index_filters_controller.rb +0 -49
- data/app/datatables/rocket_job_mission_control/completed_jobs_datatable.rb +0 -27
- data/app/datatables/rocket_job_mission_control/interrupted_jobs_datatable.rb +0 -26
- data/app/datatables/rocket_job_mission_control/queued_jobs_datatable.rb +0 -23
- data/app/datatables/rocket_job_mission_control/running_jobs_datatable.rb +0 -47
- data/app/datatables/rocket_job_mission_control/scheduled_jobs_datatable.rb +0 -31
- data/app/models/job_failures.rb +0 -20
- data/app/models/job_sanitizer.rb +0 -17
- data/app/views/layouts/rocket_job_mission_control/application.html.haml +0 -45
- data/app/views/layouts/rocket_job_mission_control/partials/_header.html.haml +0 -32
- data/app/views/layouts/rocket_job_mission_control/partials/_sidebar.html.haml +0 -11
- data/app/views/rocket_job_mission_control/active_workers/index.html.haml +0 -24
- data/app/views/rocket_job_mission_control/dirmon_entries/_form.html.haml +0 -37
- data/app/views/rocket_job_mission_control/dirmon_entries/_properties.html.haml +0 -30
- data/app/views/rocket_job_mission_control/dirmon_entries/_sidebar.html.haml +0 -27
- data/app/views/rocket_job_mission_control/dirmon_entries/_status.html.haml +0 -23
- data/app/views/rocket_job_mission_control/dirmon_entries/edit.html.haml +0 -4
- data/app/views/rocket_job_mission_control/dirmon_entries/index.html.haml +0 -18
- data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/disabled.html.haml +0 -17
- data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/enabled.html.haml +0 -17
- data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/failed.html.haml +0 -17
- data/app/views/rocket_job_mission_control/dirmon_entries/index_filters/pending.html.haml +0 -17
- data/app/views/rocket_job_mission_control/dirmon_entries/new.html.haml +0 -6
- data/app/views/rocket_job_mission_control/dirmon_entries/show.html.haml +0 -23
- data/app/views/rocket_job_mission_control/jobs/_sidebar.html.haml +0 -28
- data/app/views/rocket_job_mission_control/jobs/_status.html.haml +0 -45
- data/app/views/rocket_job_mission_control/jobs/edit.html.haml +0 -34
- data/app/views/rocket_job_mission_control/jobs/exceptions.html.haml +0 -29
- data/app/views/rocket_job_mission_control/jobs/failures/_pagination.html.haml +0 -16
- data/app/views/rocket_job_mission_control/jobs/failures/index.html.haml +0 -32
- data/app/views/rocket_job_mission_control/jobs/index.html.haml +0 -25
- data/app/views/rocket_job_mission_control/jobs/index_filters/aborted.html.haml +0 -23
- data/app/views/rocket_job_mission_control/jobs/index_filters/completed.html.haml +0 -24
- data/app/views/rocket_job_mission_control/jobs/index_filters/failed.html.haml +0 -23
- data/app/views/rocket_job_mission_control/jobs/index_filters/paused.html.haml +0 -23
- data/app/views/rocket_job_mission_control/jobs/index_filters/queued.html.haml +0 -24
- data/app/views/rocket_job_mission_control/jobs/index_filters/running.html.haml +0 -25
- data/app/views/rocket_job_mission_control/jobs/index_filters/scheduled.html.haml +0 -24
- data/app/views/rocket_job_mission_control/jobs/show.html.haml +0 -51
- data/app/views/rocket_job_mission_control/servers/_actions.html.haml +0 -9
- data/app/views/rocket_job_mission_control/servers/_sidebar.html.haml +0 -20
- data/app/views/rocket_job_mission_control/servers/index.html.haml +0 -37
- data/app/views/rocket_job_mission_control/servers/index_filters/paused.html.haml +0 -37
- data/app/views/rocket_job_mission_control/servers/index_filters/running.html.haml +0 -37
- data/app/views/rocket_job_mission_control/servers/index_filters/starting.html.haml +0 -37
- data/app/views/rocket_job_mission_control/servers/index_filters/stopping.html.haml +0 -37
- data/spec/controllers/application_controller_spec.rb +0 -47
- data/spec/controllers/dirmon_entries/index_filters_controller_spec.rb +0 -77
- data/spec/controllers/dirmon_entries_controller_spec.rb +0 -383
- data/spec/controllers/jobs/failures_controller_spec.rb +0 -82
- data/spec/controllers/jobs/index_filters_controller_spec.rb +0 -66
- data/spec/controllers/jobs_controller_spec.rb +0 -172
- data/spec/controllers/workers/index_filters_controller_spec.rb +0 -59
- data/spec/controllers/workers_controller_spec.rb +0 -125
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/mongoid.yml +0 -88
- data/spec/dummy/config/routes.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config/symmetric-encryption.yml +0 -8
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +0 -118933
- data/spec/helpers/application_helper_spec.rb +0 -58
- data/spec/helpers/jobs_helper_spec.rb +0 -35
- data/spec/helpers/pagination_helper_spec.rb +0 -21
- data/spec/helpers/servers_helper_spec.rb +0 -16
- data/spec/helpers/slices_helper_spec.rb +0 -33
- data/spec/models/job_failures_spec.rb +0 -14
- data/spec/models/job_sanitizer_spec.rb +0 -16
- data/spec/rails_helper.rb +0 -47
- data/spec/spec_helper.rb +0 -84
- data/vendor/assets/javascripts/jquery.bootstrap-touchspin.js +0 -686
- data/vendor/assets/javascripts/prism.js +0 -6
- data/vendor/assets/stylesheets/jquery.bootstrap-touchspin.css +0 -45
- data/vendor/assets/stylesheets/prism.scss +0 -160
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module RocketJobMissionControl
|
4
|
+
class ApplicationHelperTest < ActionView::TestCase
|
5
|
+
describe ApplicationHelper do
|
6
|
+
|
7
|
+
describe '#state_icon' do
|
8
|
+
RocketJobMissionControl::ApplicationHelper::STATE_ICON_MAP.each do |state, expected_class|
|
9
|
+
describe "when the job state is #{state}" do
|
10
|
+
it 'returns the correct class' do
|
11
|
+
assert_equal "#{expected_class} #{state}", state_icon(state)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#pretty_print_array_or_hash' do
|
18
|
+
let(:arguments) { [42, "muad'dib"] }
|
19
|
+
let(:helper_output) { pretty_print_array_or_hash(arguments) }
|
20
|
+
|
21
|
+
describe 'when arguments is a simple array' do
|
22
|
+
it 'returns a string with spacing and line breaks' do
|
23
|
+
assert_equal "[<br /> 42,<br /> \"muad'dib\"<br />]", helper_output
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'when arguments is an array with complex data' do
|
28
|
+
let(:arguments) {
|
29
|
+
[
|
30
|
+
42,
|
31
|
+
{
|
32
|
+
crew: ['leela', 'fry', 'bender'],
|
33
|
+
created_at: '1999-03-28',
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
37
|
+
|
38
|
+
it 'returns a string with spacing and line breaks' do
|
39
|
+
expected_output = "[<br /> 42,<br /> {<br /> \"crew\": [<br /> \"leela\",<br /> \"fry\",<br /> \"bender\"<br /> ],<br /> \"created_at\": \"1999-03-28\"<br /> }<br />]"
|
40
|
+
assert_equal expected_output, helper_output
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "when arguments isn't an array or hash" do
|
45
|
+
let(:arguments) { 42 }
|
46
|
+
|
47
|
+
it 'returns the arguments' do
|
48
|
+
assert_equal arguments, helper_output
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module RocketJobMissionControl
|
4
|
+
JobsHelper.include(RocketJobMissionControl::ApplicationHelper)
|
5
|
+
class JobsHelperTest < ActionView::TestCase
|
6
|
+
|
7
|
+
describe JobsHelper do
|
8
|
+
describe '#jobs_icon' do
|
9
|
+
let :job do
|
10
|
+
RocketJob::Jobs::SimpleJob.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'shows queued' do
|
14
|
+
assert_equal 'fa-inbox queued', job_icon(job)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'shows running' do
|
18
|
+
job.start
|
19
|
+
assert_equal 'fa-play running', job_icon(job)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'shows failed' do
|
23
|
+
job.start
|
24
|
+
job.fail
|
25
|
+
assert_equal 'fa-exclamation-triangle failed', job_icon(job)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'shows aborted' do
|
29
|
+
job.start
|
30
|
+
job.abort
|
31
|
+
assert_equal 'fa-stop aborted', job_icon(job)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'handles scheduled special case' do
|
35
|
+
job.run_at = 1.day.from_now
|
36
|
+
assert_equal 'fa-clock-o scheduled', job_icon(job)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#jobs_states' do
|
41
|
+
it 'returns the states' do
|
42
|
+
assert_equal %w(queued running completed paused failed aborted), job_states
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#job_states_with_scheduled' do
|
47
|
+
it 'returns the states with scheduled' do
|
48
|
+
assert_equal %w(scheduled queued running completed paused failed aborted), job_states_with_scheduled
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#job_counts_by_state' do
|
53
|
+
it 'returns job counts for a state' do
|
54
|
+
RocketJob::Job.delete_all
|
55
|
+
RocketJob::Jobs::SimpleJob.create!
|
56
|
+
assert_equal 1, job_counts_by_state(:queued), RocketJob::Job.counts_by_state
|
57
|
+
assert_equal 0, job_counts_by_state(:running), RocketJob::Job.counts_by_state
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#job_action_link' do
|
62
|
+
let(:action) { 'abort' }
|
63
|
+
let(:http_method) { :patch }
|
64
|
+
let(:path) { "/jobs/42/#{action}" }
|
65
|
+
let(:action_link) { job_action_link(action, path, http_method) }
|
66
|
+
|
67
|
+
it 'uses the action as the label' do
|
68
|
+
assert_match />abort<\/a>/, action_link
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'links to the correct url' do
|
72
|
+
assert_match /href="\/jobs\/42\/abort\"/, action_link
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'adds prompt for confirmation' do
|
76
|
+
assert_match /data-confirm="Are you sure you want to abort this job\?"/, action_link
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'uses correct http method' do
|
80
|
+
assert_match /data-method="patch"/, action_link
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module RocketJobMissionControl
|
4
|
+
class PaginationHelperTest < ActionView::TestCase
|
5
|
+
describe PaginationHelper do
|
6
|
+
|
7
|
+
describe '#page_nav_disabled_class' do
|
8
|
+
describe 'when the current position equals the boundary' do
|
9
|
+
it 'returns disabled' do
|
10
|
+
assert_equal 'disabled', page_nav_disabled_class(0, 0)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'when the current position is NOT equal to the boundary' do
|
15
|
+
it 'returns blank' do
|
16
|
+
assert page_nav_disabled_class(4, 0).blank?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module RocketJobMissionControl
|
4
|
+
ServersHelper.include(RocketJobMissionControl::ApplicationHelper)
|
5
|
+
class ServersHelperTest < ActionView::TestCase
|
6
|
+
describe ServersHelper do
|
7
|
+
|
8
|
+
describe '#server_card_class' do
|
9
|
+
describe 'when the server is running' do
|
10
|
+
let(:server) do
|
11
|
+
server = RocketJob::Server.new
|
12
|
+
server.started
|
13
|
+
server.build_heartbeat(updated_at: Time.now, workers: 0)
|
14
|
+
server
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns the correct class' do
|
18
|
+
assert_equal 'callout-success', server_card_class(server)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'when the server is a zombie' do
|
23
|
+
let(:server) do
|
24
|
+
server = RocketJob::Server.new
|
25
|
+
server.started
|
26
|
+
server
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the correct class' do
|
30
|
+
assert_equal 'callout-zombie', server_card_class(server)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#server_icon' do
|
36
|
+
describe 'when the server is running' do
|
37
|
+
let(:server) do
|
38
|
+
server = RocketJob::Server.new
|
39
|
+
server.started
|
40
|
+
server.build_heartbeat(updated_at: Time.now, workers: 0)
|
41
|
+
server
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the correct class' do
|
45
|
+
assert_equal 'fa-play running', server_icon(server)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'when the server is a zombie' do
|
50
|
+
let(:server) do
|
51
|
+
server = RocketJob::Server.new
|
52
|
+
server.started
|
53
|
+
server
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns the correct class' do
|
57
|
+
assert_equal 'fa-hourglass-o zombie', server_icon(server)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
module RocketJobMissionControl
|
4
|
+
SlicesHelper.include(RocketJobMissionControl::ApplicationHelper)
|
5
|
+
class SlicesHelperTest < ActionView::TestCase
|
6
|
+
describe SlicesHelper do
|
7
|
+
|
8
|
+
describe '#display_slice_info' do
|
9
|
+
let(:slice) { {id: 42, name: 'test'} }
|
10
|
+
|
11
|
+
describe 'when encrypted' do
|
12
|
+
it 'only shows encrypted text' do
|
13
|
+
assert_equal 'encrypted', display_slice_info(slice, true)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'when not encrypted' do
|
18
|
+
it "does not return 'encrypted'" do
|
19
|
+
refute_equal 'encrypted', display_slice_info([1,2], false)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "displays the slice info" do
|
23
|
+
assert_equal "[<br /> 1,<br /> 2<br />]", display_slice_info([1,2], false)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class JobSanitizerTest < Minitest::Test
|
4
|
+
describe RocketJobMissionControl::JobSanitizer do
|
5
|
+
before do
|
6
|
+
@job = AllTypesJob.new
|
7
|
+
assert_equal 0, @job.errors.count
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.sanitize' do
|
14
|
+
it 'passes permissible fields' do
|
15
|
+
properties = {
|
16
|
+
string: 'hello',
|
17
|
+
integer: '12',
|
18
|
+
symbol: 'name',
|
19
|
+
secure: 'Not permissible'
|
20
|
+
}
|
21
|
+
cleansed = RocketJobMissionControl::JobSanitizer.sanitize(properties, @job.class, @job, false)
|
22
|
+
assert_equal 0, @job.errors.count
|
23
|
+
assert_equal 3, cleansed.count
|
24
|
+
assert_equal({:string=>"hello", :integer=>"12", :symbol=>"name"}, cleansed)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'strips blank values' do
|
28
|
+
properties = {
|
29
|
+
string: '',
|
30
|
+
integer: '',
|
31
|
+
symbol: '',
|
32
|
+
secure: 'Not permissible',
|
33
|
+
log_level: ''
|
34
|
+
}
|
35
|
+
cleansed = RocketJobMissionControl::JobSanitizer.sanitize(properties, @job.class, @job, false)
|
36
|
+
assert_equal 0, @job.errors.count
|
37
|
+
assert_equal 0, cleansed.count
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'nils blank values' do
|
41
|
+
properties = {
|
42
|
+
string: '',
|
43
|
+
integer: '',
|
44
|
+
symbol: '',
|
45
|
+
hash: '',
|
46
|
+
secure: 'Not permissible',
|
47
|
+
log_level: ''
|
48
|
+
}
|
49
|
+
cleansed = RocketJobMissionControl::JobSanitizer.sanitize(properties, @job.class, @job, true)
|
50
|
+
assert_equal 0, @job.errors.count, @job.errors
|
51
|
+
assert_equal 5, cleansed.count
|
52
|
+
assert_equal({log_level: nil, hash: nil, integer: nil, string: nil, symbol: nil}, cleansed)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'parses JSON' do
|
56
|
+
properties = {
|
57
|
+
string: '',
|
58
|
+
secure: 'Not permissible',
|
59
|
+
hash: '{"state":"FL"}'
|
60
|
+
}
|
61
|
+
cleansed = RocketJobMissionControl::JobSanitizer.sanitize(properties, @job.class, @job, false)
|
62
|
+
assert_equal 0, @job.errors.count
|
63
|
+
assert_equal 1, cleansed.count
|
64
|
+
assert_equal({'state' => 'FL'}, cleansed[:hash])
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'sets the error for invalid JSON' do
|
68
|
+
properties = {
|
69
|
+
string: 'hello',
|
70
|
+
secure: 'Not permissible',
|
71
|
+
hash: '{ bad json }'
|
72
|
+
}
|
73
|
+
cleansed = RocketJobMissionControl::JobSanitizer.sanitize(properties, @job.class, @job, false)
|
74
|
+
assert_equal 1, @job.errors.count
|
75
|
+
assert first = @job.errors.first
|
76
|
+
assert_equal first.first, :properties
|
77
|
+
assert first.second.include?('unexpected token'), first
|
78
|
+
assert_equal({hash: "{ bad json }", string: 'hello'}, cleansed)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'Keeps empty JSON Hash' do
|
82
|
+
properties = {
|
83
|
+
hash: '{ }'
|
84
|
+
}
|
85
|
+
cleansed = RocketJobMissionControl::JobSanitizer.sanitize(properties, @job.class, @job, false)
|
86
|
+
assert_equal 0, @job.errors.count
|
87
|
+
assert_equal({hash: {}}, cleansed)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class QueryTest < Minitest::Test
|
4
|
+
|
5
|
+
class NoopJob < RocketJob::Job
|
6
|
+
def perform(record)
|
7
|
+
# noop
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe RocketJobMissionControl::Query do
|
12
|
+
before do
|
13
|
+
@jobs = (1..10).collect { |i| NoopJob.create(description: "Job #{i}") }
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
NoopJob.delete_all
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#query' do
|
21
|
+
it 'sorts ascending by id' do
|
22
|
+
count = 0
|
23
|
+
previous_id = nil
|
24
|
+
RocketJobMissionControl::Query.new(NoopJob.all, _id: 1).query.each do |job|
|
25
|
+
assert(previous_id < job.id, "Wrong sort order. #{previous_id} < #{job.id}") if previous_id
|
26
|
+
previous_id = job.id
|
27
|
+
count += 1
|
28
|
+
end
|
29
|
+
assert_equal @jobs.count, count
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'sorts descending by id' do
|
33
|
+
count = 0
|
34
|
+
previous_id = nil
|
35
|
+
RocketJobMissionControl::Query.new(NoopJob.all, _id: -1).query.each do |job|
|
36
|
+
assert(previous_id > job.id, "Wrong sort order. #{previous_id} > #{job.id}") if previous_id
|
37
|
+
previous_id = job.id
|
38
|
+
count += 1
|
39
|
+
end
|
40
|
+
assert_equal @jobs.count, count
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'sorts ascending by description' do
|
44
|
+
count = 0
|
45
|
+
previous = nil
|
46
|
+
RocketJobMissionControl::Query.new(NoopJob.all, description: 1).query.each do |job|
|
47
|
+
assert(previous < job.description, "Wrong sort order. #{previous} < #{job.description}") if previous
|
48
|
+
previous = job.description
|
49
|
+
count += 1
|
50
|
+
end
|
51
|
+
assert_equal @jobs.count, count
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'sorts ascending by id with a search' do
|
55
|
+
q = RocketJobMissionControl::Query.new(NoopJob.all, description: 1)
|
56
|
+
q.search_columns << :description
|
57
|
+
q.search_term = 'Job 1'
|
58
|
+
|
59
|
+
count = 0
|
60
|
+
previous_id = nil
|
61
|
+
q.query.each do |job|
|
62
|
+
assert(previous_id < job.id, "Wrong sort order. #{previous_id} < #{job.id}") if previous_id
|
63
|
+
previous_id = job.id
|
64
|
+
count += 1
|
65
|
+
end
|
66
|
+
assert_equal 2, count
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'paginates with sort' do
|
70
|
+
q = RocketJobMissionControl::Query.new(NoopJob.all, _id: 1)
|
71
|
+
q.start = 1
|
72
|
+
q.page_size = 3
|
73
|
+
|
74
|
+
count = 0
|
75
|
+
previous_id = nil
|
76
|
+
q.query.each do |job|
|
77
|
+
assert(previous_id < job.id, "Wrong sort order. #{previous_id} < #{job.id}") if previous_id
|
78
|
+
previous_id = job.id
|
79
|
+
count += 1
|
80
|
+
end
|
81
|
+
assert_equal 3, count
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'paginates with sort and search' do
|
85
|
+
q = RocketJobMissionControl::Query.new(NoopJob.all, _id: 1)
|
86
|
+
q.search_columns << :description
|
87
|
+
q.search_term = 'Job'
|
88
|
+
q.start = 1
|
89
|
+
q.page_size = 3
|
90
|
+
|
91
|
+
count = 0
|
92
|
+
previous_id = nil
|
93
|
+
q.query.each do |job|
|
94
|
+
assert(previous_id < job.id, "Wrong sort order. #{previous_id} < #{job.id}") if previous_id
|
95
|
+
previous_id = job.id
|
96
|
+
count += 1
|
97
|
+
end
|
98
|
+
assert_equal 3, count
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#count' do
|
104
|
+
it 'without search' do
|
105
|
+
assert_equal 10, RocketJobMissionControl::Query.new(NoopJob.all, description: 1).count
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'with search and pagination' do
|
109
|
+
q = RocketJobMissionControl::Query.new(NoopJob.all, description: 1)
|
110
|
+
q.search_columns << :description
|
111
|
+
q.search_term = 'Job 1'
|
112
|
+
# Pagination should be ignored
|
113
|
+
q.start = 1
|
114
|
+
q.page_size = 1
|
115
|
+
assert_equal 2, q.count
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#unfiltered_count' do
|
120
|
+
it 'without search' do
|
121
|
+
assert_equal 10, RocketJobMissionControl::Query.new(NoopJob.all, description: 1).unfiltered_count
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'with search and pagination' do
|
125
|
+
q = RocketJobMissionControl::Query.new(NoopJob.all, description: 1)
|
126
|
+
q.search_columns << :description
|
127
|
+
q.search_term = 'Job 1'
|
128
|
+
# Pagination should be ignored
|
129
|
+
q.start = 1
|
130
|
+
q.page_size = 3
|
131
|
+
assert_equal 10, q.unfiltered_count
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|