rocketjob_mission_control 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require 'rails_helper'
1
+ require_relative '../rails_helper'
2
2
 
3
3
  class FakeButGoodJob < RocketJob::Job
4
4
 
@@ -29,11 +29,11 @@ module RocketJobMissionControl
29
29
 
30
30
  let(:existing_dirmon) do
31
31
  RocketJob::DirmonEntry.create!(
32
- name: 'Test',
33
- job_class_name: 'FakeButGoodJob',
34
- pattern: 'the_path',
35
- arguments: [ 42 ].to_json,
36
- state: starting_state,
32
+ name: 'Test',
33
+ job_class_name: 'FakeButGoodJob',
34
+ pattern: 'the_path',
35
+ arguments: ['42'],
36
+ state: starting_state,
37
37
  )
38
38
  end
39
39
 
@@ -61,11 +61,11 @@ module RocketJobMissionControl
61
61
  describe 'PATCH #disable' do
62
62
  let(:existing_dirmon) do
63
63
  RocketJob::DirmonEntry.create!(
64
- name: 'Test',
65
- job_class_name: 'FakeButGoodJob',
66
- pattern: 'the_path',
67
- arguments: [ 42 ].to_json,
68
- state: starting_state,
64
+ name: 'Test',
65
+ job_class_name: 'FakeButGoodJob',
66
+ pattern: 'the_path',
67
+ arguments: ['42'],
68
+ state: starting_state,
69
69
  )
70
70
  end
71
71
 
@@ -78,7 +78,7 @@ module RocketJobMissionControl
78
78
 
79
79
  it { expect(response).to redirect_to(dirmon_entry_path(existing_dirmon.id)) }
80
80
 
81
- it "changes the state to disabled" do
81
+ it 'changes the state to disabled' do
82
82
  expect(existing_dirmon.reload.state).to eq(:disabled)
83
83
  end
84
84
  end
@@ -95,8 +95,10 @@ module RocketJobMissionControl
95
95
  end
96
96
 
97
97
  describe 'GET #new' do
98
+ let(:entry_params) { {} }
99
+
98
100
  before do
99
- get :new
101
+ get :new, entry_params
100
102
  end
101
103
 
102
104
  it { expect(response.status).to eq(200) }
@@ -105,15 +107,37 @@ module RocketJobMissionControl
105
107
  expect(assigns(:dirmon_entry)).to be_present
106
108
  expect(assigns(:dirmon_entry)).to_not be_persisted
107
109
  end
110
+
111
+ context 'with a valid job_class_name' do
112
+ let(:entry_params) { { job_class_name: 'FakeButGoodJob' } }
113
+
114
+ it { expect(response.status).to eq(200) }
115
+
116
+ it 'assigns the job class' do
117
+ expect(assigns(:dirmon_entry)).to be_present
118
+ expect(assigns(:dirmon_entry).job_class).to eq(FakeButGoodJob)
119
+ end
120
+ end
121
+
122
+ context 'with an invalid job_class_name' do
123
+ let(:entry_params) { { job_class_name: 'BadJob' } }
124
+
125
+ it { expect(response.status).to eq(200) }
126
+
127
+ it 'adds an error' do
128
+ expect(assigns(:dirmon_entry)).to be_present
129
+ expect(assigns(:dirmon_entry).errors[:job_class_name]).to be_present
130
+ end
131
+ end
108
132
  end
109
133
 
110
134
  describe 'PATCH #update' do
111
135
  let(:existing_dirmon) do
112
136
  RocketJob::DirmonEntry.create!(
113
- name: 'Test',
114
- job_class_name: 'FakeButGoodJob',
115
- pattern: 'the_path',
116
- arguments: [ 42 ].to_json
137
+ name: 'Test',
138
+ job_class_name: 'FakeButGoodJob',
139
+ pattern: 'the_path',
140
+ arguments: ['{"argument1":"value1", "argument2":"value2", "argument3":"value3"}']
117
141
  )
118
142
  end
119
143
 
@@ -124,9 +148,9 @@ module RocketJobMissionControl
124
148
  context 'with valid parameters' do
125
149
  let(:dirmon_params) do
126
150
  {
127
- pattern: 'the_path2',
128
- job_class_name: 'FakeButGoodJob',
129
- arguments: [ 42 ].to_json
151
+ pattern: 'the_path2',
152
+ job_class_name: 'FakeButGoodJob',
153
+ arguments: ['42']
130
154
  }
131
155
  end
132
156
 
@@ -166,9 +190,9 @@ module RocketJobMissionControl
166
190
  context 'with invalid arguments json' do
167
191
  let(:dirmon_params) do
168
192
  {
169
- name: 'Test',
193
+ name: 'Test',
170
194
  job_class_name: 'FakeButGoodJob',
171
- arguments: "['42']",
195
+ arguments: [],
172
196
  }
173
197
  end
174
198
 
@@ -192,17 +216,18 @@ module RocketJobMissionControl
192
216
  context 'with valid parameters' do
193
217
 
194
218
  {
195
- perform: { argument: [42].to_json, expected_value: [42] },
196
- perform_with_no_params: { argument: '', expected_value: [] },
219
+ perform: {argument: ['42'], expected_value: [42]},
220
+ perform: {argument: ['{"argument1":"value1", "argument2":"value2", "argument3":"value3"}'], expected_value: [{"argument1" => "value1", "argument2" => "value2", "argument3" => "value3"}]},
221
+ perform_with_no_params: {argument: [], expected_value: []},
197
222
  }.each_pair do |perform_method, arguments|
198
223
  context "and arguments are '#{arguments}'" do
199
224
  let(:dirmon_params) do
200
225
  {
201
- name: 'Test',
202
- pattern: '/files/',
226
+ name: 'Test',
227
+ pattern: '/files/*',
203
228
  job_class_name: 'FakeButGoodJob',
204
- arguments: arguments[:argument],
205
- properties: { description: '', priority: 42 },
229
+ arguments: arguments[:argument],
230
+ properties: {description: '', priority: 42},
206
231
  perform_method: perform_method,
207
232
  }
208
233
  end
@@ -251,9 +276,9 @@ module RocketJobMissionControl
251
276
  context 'with invalid parameters' do
252
277
  let(:dirmon_params) do
253
278
  {
254
- name: 'Test',
279
+ name: 'Test',
255
280
  job_class_name: 'FakeAndBadJob',
256
- arguments: [ 42 ].to_json,
281
+ arguments: [[42].to_json],
257
282
  }
258
283
  end
259
284
 
@@ -279,9 +304,9 @@ module RocketJobMissionControl
279
304
  context 'with invalid arguments json' do
280
305
  let(:dirmon_params) do
281
306
  {
282
- name: 'Test',
307
+ name: 'Test',
283
308
  job_class_name: 'FakeButGoodJob',
284
- arguments: "['42']",
309
+ arguments: ['{"bad" "json"}'],
285
310
  }
286
311
  end
287
312
 
@@ -304,10 +329,10 @@ module RocketJobMissionControl
304
329
  describe 'GET #edit' do
305
330
  before do
306
331
  @entry = RocketJob::DirmonEntry.create(
307
- name: 'Test',
308
- pattern: '/files/',
309
- job_class_name: 'FakeButGoodJob',
310
- arguments: [ 42 ]
332
+ name: 'Test',
333
+ pattern: '/files/',
334
+ job_class_name: 'FakeButGoodJob',
335
+ arguments: [42]
311
336
  )
312
337
  get :edit, id: @entry.id
313
338
  end
@@ -321,40 +346,40 @@ module RocketJobMissionControl
321
346
  end
322
347
 
323
348
  describe 'GET #show' do
324
- describe "with an invalid id" do
349
+ describe 'with an invalid id' do
325
350
  before do
326
351
  allow(RocketJob::DirmonEntry).to receive(:find).and_return(nil)
327
352
  get :show, id: 42
328
353
  end
329
354
 
330
- it "redirects" do
355
+ it 'redirects' do
331
356
  expect(response).to redirect_to(dirmon_entries_path)
332
357
  end
333
358
 
334
- it "adds a flash alert message" do
359
+ it 'adds a flash alert message' do
335
360
  expect(flash[:alert]).to eq(I18n.t(:failure, scope: [:dirmon_entry, :find], id: 42))
336
361
  end
337
362
  end
338
363
 
339
- describe "with a valid id" do
364
+ describe 'with a valid id' do
340
365
  before do
341
366
  allow(RocketJob::DirmonEntry).to receive(:find).and_return('entry')
342
367
  get :show, id: 42
343
368
  end
344
369
 
345
- it "succeeds" do
370
+ it 'succeeds' do
346
371
  expect(response.status).to be(200)
347
372
  end
348
373
 
349
- it "assigns the entry" do
374
+ it 'assigns the entry' do
350
375
  expect(assigns(:dirmon_entry)).to be_present
351
376
  end
352
377
 
353
- it "assigns the entries" do
378
+ it 'assigns the entries' do
354
379
  expect(assigns(:dirmons)).to eq([])
355
380
  end
356
381
 
357
- it "grabs a sorted list" do
382
+ it 'grabs a sorted list' do
358
383
  expect(dirmon_list).to have_received(:sort).with(created_at: :desc)
359
384
  end
360
385
  end
@@ -363,10 +388,10 @@ module RocketJobMissionControl
363
388
  describe 'DELETE #destroy' do
364
389
  let(:existing_dirmon) do
365
390
  RocketJob::DirmonEntry.create!(
366
- name: 'Test',
367
- job_class_name: 'FakeButGoodJob',
368
- pattern: 'the_path',
369
- arguments: [ 42 ].to_json
391
+ name: 'Test',
392
+ job_class_name: 'FakeButGoodJob',
393
+ pattern: 'the_path',
394
+ arguments: [42].to_json
370
395
  )
371
396
  end
372
397
 
@@ -388,73 +413,73 @@ module RocketJobMissionControl
388
413
  end
389
414
 
390
415
  describe 'GET #index' do
391
- describe "with no entries" do
416
+ describe 'with no entries' do
392
417
  before do
393
418
  get :index
394
419
  end
395
420
 
396
- it "succeeds" do
421
+ it 'succeeds' do
397
422
  expect(response.status).to be(200)
398
423
  end
399
424
 
400
- it "grabs a sorted list of entries" do
425
+ it 'grabs a sorted list of entries' do
401
426
  expect(dirmon_list).to have_received(:sort).with(created_at: :desc)
402
427
  end
403
428
 
404
- it "returns no entries" do
429
+ it 'returns no entries' do
405
430
  expect(assigns(:dirmons)).to eq([])
406
431
  end
407
432
  end
408
433
 
409
- describe "with jobs" do
434
+ describe 'with jobs' do
410
435
  let(:dirmon_list) { spy(sort: dirmons) }
411
436
  let(:dirmons) { ['fake_dirmon1', 'fake_dirmon2'] }
412
437
 
413
- describe "with no parameters" do
438
+ describe 'with no parameters' do
414
439
  before { get :index }
415
440
 
416
- it "succeeds" do
441
+ it 'succeeds' do
417
442
  expect(response.status).to be(200)
418
443
  end
419
444
 
420
- it "grabs a sorted list of entries" do
445
+ it 'grabs a sorted list of entries' do
421
446
  expect(dirmon_list).to have_received(:sort).with(created_at: :desc)
422
447
  end
423
448
 
424
- it "returns the entries" do
449
+ it 'returns the entries' do
425
450
  expect(assigns(:dirmons)).to match_array(dirmons)
426
451
  end
427
452
  end
428
453
 
429
- describe "with a state filter" do
430
- before { get :index, states: states}
454
+ describe 'with a state filter' do
455
+ before { get :index, states: states }
431
456
 
432
- context "that is empty" do
457
+ context 'that is empty' do
433
458
  let(:states) { [] }
434
459
 
435
460
  it { expect(response.status).to be(200) }
436
461
 
437
- it "grabs a sorted list" do
462
+ it 'grabs a sorted list' do
438
463
  expect(dirmon_list).to have_received(:sort).with(created_at: :desc)
439
464
  end
440
465
 
441
- it "returns the entries" do
466
+ it 'returns the entries' do
442
467
  expect(assigns(:dirmons)).to match_array(dirmons)
443
468
  end
444
469
  end
445
470
 
446
- context "with a state" do
471
+ context 'with a state' do
447
472
  let(:query_spy) { spy(where: dirmons) }
448
473
  let(:dirmon_list) { spy(sort: query_spy) }
449
474
  let(:states) { ['enabled'] }
450
475
 
451
476
  it { expect(response.status).to be(200) }
452
477
 
453
- it "grabs a filtered list" do
478
+ it 'grabs a filtered list' do
454
479
  expect(query_spy).to have_received(:where).with(state: ['enabled'])
455
480
  end
456
481
 
457
- it "returns the entries" do
482
+ it 'returns the entries' do
458
483
  expect(assigns(:dirmons)).to match_array(dirmons)
459
484
  end
460
485
  end
@@ -1,2 +1,4 @@
1
1
  MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
2
2
  MONGODB (0.5ms) admin['$cmd'].find({:isMaster=>1}).limit(-1)
3
+ MONGODB [DEBUG] Logging level is currently :debug which could negatively impact client-side performance. You should set your logging level no lower than :info in production.
4
+ MONGODB (0.4ms) admin['$cmd'].find({:isMaster=>1}).limit(-1)