Added tests for scheduler fields error_message and status.
This commit is contained in:
parent
63aa9142af
commit
80199a61b5
2 changed files with 43 additions and 0 deletions
25
spec/factories/scheduler.rb
Normal file
25
spec/factories/scheduler.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
sequence :test_scheduler_name do |n|
|
||||||
|
"Testscheduler#{n}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
FactoryGirl.define do
|
||||||
|
|
||||||
|
factory :scheduler do
|
||||||
|
name { generate(:test_scheduler_name) }
|
||||||
|
last_run { Time.zone.now }
|
||||||
|
pid 1337
|
||||||
|
prio 1
|
||||||
|
status 'ok'
|
||||||
|
active true
|
||||||
|
period { 10.minutes }
|
||||||
|
running false
|
||||||
|
note 'test'
|
||||||
|
updated_by_id 1
|
||||||
|
created_by_id 1
|
||||||
|
created_at 1
|
||||||
|
updated_at 1
|
||||||
|
add_attribute(:method) { 'test' }
|
||||||
|
end
|
||||||
|
end
|
|
@ -26,6 +26,24 @@ RSpec.describe Scheduler do
|
||||||
SpecSpace.send(:remove_const, :DelayedJobBackend)
|
SpecSpace.send(:remove_const, :DelayedJobBackend)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '._start_job' do
|
||||||
|
|
||||||
|
it 'sets error status/message for failed jobs' do
|
||||||
|
job = create(:scheduler)
|
||||||
|
described_class._start_job(job)
|
||||||
|
expect(job.status).to eq 'error'
|
||||||
|
expect(job.active).to be false
|
||||||
|
expect(job.error_message).to be_present
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'executes job that is expected to succeed' do
|
||||||
|
expect(Setting).to receive(:reload)
|
||||||
|
job = create(:scheduler, method: 'Setting.reload')
|
||||||
|
described_class._start_job(job)
|
||||||
|
expect(job.status).to eq 'ok'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '.cleanup' do
|
describe '.cleanup' do
|
||||||
|
|
||||||
it 'gets called by .threads' do
|
it 'gets called by .threads' do
|
||||||
|
|
Loading…
Reference in a new issue