gitlab-org--gitlab-foss/spec/workers/trigger_schedule_worker_spe...

74 lines
1.9 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe TriggerScheduleWorker do
2017-03-23 15:18:13 +00:00
let(:worker) { described_class.new }
2017-03-23 15:18:13 +00:00
before do
stub_ci_pipeline_to_return_yaml_file
end
context 'when there is a scheduled trigger within next_run_at' do
2017-04-07 14:02:13 +00:00
let(:next_run_at) { 2.days.ago }
let!(:trigger_schedule) do
create(:ci_trigger_schedule, :nightly)
end
2017-03-23 15:18:13 +00:00
before do
2017-04-07 14:02:13 +00:00
trigger_schedule.update_column(:next_run_at, next_run_at)
2017-03-23 15:18:13 +00:00
end
2017-03-29 13:14:58 +00:00
it 'creates a new trigger request' do
2017-04-07 14:02:13 +00:00
expect { worker.perform }.to change { Ci::TriggerRequest.count }
2017-03-29 13:14:58 +00:00
end
2017-03-23 15:18:13 +00:00
it 'creates a new pipeline' do
2017-04-07 14:02:13 +00:00
expect { worker.perform }.to change { Ci::Pipeline.count }
2017-04-06 09:55:16 +00:00
expect(Ci::Pipeline.last).to be_pending
2017-03-23 15:18:13 +00:00
end
2017-03-31 10:08:39 +00:00
it 'updates next_run_at' do
2017-04-07 14:02:13 +00:00
worker.perform
expect(trigger_schedule.reload.next_run_at).not_to eq(next_run_at)
end
context 'inactive schedule' do
before do
trigger_schedule.update(active: false)
end
it 'does not create a new trigger' do
expect { worker.perform }.not_to change { Ci::TriggerRequest.count }
end
2017-03-23 15:18:13 +00:00
end
end
2017-03-31 10:08:39 +00:00
context 'when there are no scheduled triggers within next_run_at' do
2017-04-06 10:13:29 +00:00
before { create(:ci_trigger_schedule, :nightly) }
2017-03-23 15:18:13 +00:00
it 'does not create a new pipeline' do
2017-04-06 10:13:29 +00:00
expect { worker.perform }.not_to change { Ci::Pipeline.count }
2017-03-23 15:18:13 +00:00
end
it 'does not update next_run_at' do
2017-04-06 10:13:29 +00:00
expect { worker.perform }.not_to change { Ci::TriggerSchedule.last.next_run_at }
end
end
2017-04-06 09:52:48 +00:00
context 'when next_run_at is nil' do
2017-04-07 16:05:39 +00:00
before
schedule = create(:ci_trigger_schedule, :nightly)
schedule.update_column(:next_run_at, nil)
end
2017-04-06 09:52:48 +00:00
it 'does not create a new pipeline' do
2017-04-06 10:13:29 +00:00
expect { worker.perform }.not_to change { Ci::Pipeline.count }
2017-04-06 09:52:48 +00:00
end
it 'does not update next_run_at' do
2017-04-06 10:13:29 +00:00
expect { worker.perform }.not_to change { Ci::TriggerSchedule.last.next_run_at }
2017-04-06 09:52:48 +00:00
end
end
end