gitlab-org--gitlab-foss/spec/workers/trigger_schedule_worker_spec.rb

74 lines
1.9 KiB
Ruby
Raw Normal View History

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