From 80199a61b535984c574cdb26c5c08bb1123c7b0d Mon Sep 17 00:00:00 2001 From: Jens Pfeifer Date: Thu, 7 Sep 2017 15:17:06 +0000 Subject: [PATCH] Added tests for scheduler fields error_message and status. --- spec/factories/scheduler.rb | 25 +++++++++++++++++++++++++ spec/models/scheduler_spec.rb | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 spec/factories/scheduler.rb diff --git a/spec/factories/scheduler.rb b/spec/factories/scheduler.rb new file mode 100644 index 000000000..5b484c9a1 --- /dev/null +++ b/spec/factories/scheduler.rb @@ -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 diff --git a/spec/models/scheduler_spec.rb b/spec/models/scheduler_spec.rb index 7432186d0..44e0df6b0 100644 --- a/spec/models/scheduler_spec.rb +++ b/spec/models/scheduler_spec.rb @@ -26,6 +26,24 @@ RSpec.describe Scheduler do SpecSpace.send(:remove_const, :DelayedJobBackend) 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 it 'gets called by .threads' do