Commit fff6afba authored by Shinya Maeda's avatar Shinya Maeda

Use change direction in spec

parent 059ec792
......@@ -8,58 +8,51 @@ describe TriggerScheduleWorker do
end
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
@time_future = Time.now + 10.days
allow(Time).to receive(:now).and_return(@time_future)
worker.perform
trigger_schedule = create(:ci_trigger_schedule, :nightly)
time_future = Time.now + 10.days
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
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
it 'creates a new pipeline' do
expect { worker.perform }.to change { Ci::Pipeline.count }.by(1)
expect(Ci::Pipeline.last).to be_pending
end
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
context 'when there are no scheduled triggers within next_run_at' do
let!(:trigger_schedule) { create(:ci_trigger_schedule, :nightly) }
before do
worker.perform
end
before { create(:ci_trigger_schedule, :nightly) }
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
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
context 'when next_run_at is nil' do
let!(:trigger_schedule) { create(:ci_trigger_schedule, :nightly) }
before do
trigger_schedule = create(:ci_trigger_schedule, :nightly)
trigger_schedule.update_attribute(:next_run_at, nil)
worker.perform
end
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
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
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