Commit fff6afba authored by Shinya Maeda's avatar Shinya Maeda

Use change direction in spec

parent 059ec792
...@@ -8,58 +8,51 @@ describe TriggerScheduleWorker do ...@@ -8,58 +8,51 @@ describe TriggerScheduleWorker do
end end
context 'when there is a scheduled trigger within next_run_at' do context 'when there is a scheduled trigger within next_run_at' do
let!(:trigger_schedule) { create(:ci_trigger_schedule, :nightly) }
let(:next_time) { Gitlab::Ci::CronParser.new(trigger_schedule.cron, trigger_schedule.cron_timezone).next_time_from(@time_future) }
before do before do
@time_future = Time.now + 10.days trigger_schedule = create(:ci_trigger_schedule, :nightly)
allow(Time).to receive(:now).and_return(@time_future) time_future = Time.now + 10.days
worker.perform allow(Time).to receive(:now).and_return(time_future)
@next_time = Gitlab::Ci::CronParser.new(trigger_schedule.cron, trigger_schedule.cron_timezone).next_time_from(time_future)
end end
it 'creates a new trigger request' do it 'creates a new trigger request' do
expect(trigger_schedule.trigger.id).to eq(Ci::TriggerRequest.first.trigger_id) expect { worker.perform }.to change { Ci::TriggerRequest.count }.by(1)
end end
it 'creates a new pipeline' do it 'creates a new pipeline' do
expect { worker.perform }.to change { Ci::Pipeline.count }.by(1)
expect(Ci::Pipeline.last).to be_pending expect(Ci::Pipeline.last).to be_pending
end end
it 'updates next_run_at' do it 'updates next_run_at' do
expect(Ci::TriggerSchedule.last.next_run_at).to eq(next_time) expect { worker.perform }.to change { Ci::TriggerSchedule.last.next_run_at }.to(@next_time)
end end
end end
context 'when there are no scheduled triggers within next_run_at' do context 'when there are no scheduled triggers within next_run_at' do
let!(:trigger_schedule) { create(:ci_trigger_schedule, :nightly) } before { create(:ci_trigger_schedule, :nightly) }
before do
worker.perform
end
it 'does not create a new pipeline' do it 'does not create a new pipeline' do
expect(Ci::Pipeline.count).to eq(0) expect { worker.perform }.not_to change { Ci::Pipeline.count }
end end
it 'does not update next_run_at' do it 'does not update next_run_at' do
expect(trigger_schedule.next_run_at).to eq(Ci::TriggerSchedule.last.next_run_at) expect { worker.perform }.not_to change { Ci::TriggerSchedule.last.next_run_at }
end end
end end
context 'when next_run_at is nil' do context 'when next_run_at is nil' do
let!(:trigger_schedule) { create(:ci_trigger_schedule, :nightly) }
before do before do
trigger_schedule = create(:ci_trigger_schedule, :nightly)
trigger_schedule.update_attribute(:next_run_at, nil) trigger_schedule.update_attribute(:next_run_at, nil)
worker.perform
end end
it 'does not create a new pipeline' do it 'does not create a new pipeline' do
expect(Ci::Pipeline.count).to eq(0) expect { worker.perform }.not_to change { Ci::Pipeline.count }
end end
it 'does not update next_run_at' do it 'does not update next_run_at' do
expect(trigger_schedule.next_run_at).to eq(Ci::TriggerSchedule.last.next_run_at) expect { worker.perform }.not_to change { Ci::TriggerSchedule.last.next_run_at }
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment