debian-mirror-gitlab/spec/workers/pipeline_schedule_worker_spec.rb

66 lines
1.6 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe PipelineScheduleWorker do
subject { described_class.new.perform }
set(:project) { create(:project, :repository) }
set(:user) { create(:user) }
let!(:pipeline_schedule) do
create(:ci_pipeline_schedule, :nightly, project: project, owner: user)
end
before do
stub_ci_pipeline_to_return_yaml_file
2017-09-10 17:25:29 +05:30
pipeline_schedule.update_column(:next_run_at, 1.day.ago)
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
context 'when the schedule is runnable by the user' do
2017-08-17 22:00:37 +05:30
before do
2017-09-10 17:25:29 +05:30
project.add_master(user)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
context 'when there is a scheduled pipeline within next_run_at' do
it 'creates a new pipeline' do
expect{ subject }.to change { project.pipelines.count }.by(1)
expect(Ci::Pipeline.last).to be_schedule
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
it 'updates the next_run_at field' do
subject
expect(pipeline_schedule.reload.next_run_at).to be > Time.now
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
it 'sets the schedule on the pipeline' do
subject
expect(project.pipelines.last.pipeline_schedule).to eq(pipeline_schedule)
end
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
context 'inactive schedule' do
before do
pipeline_schedule.deactivate!
end
it 'does not creates a new pipeline' do
expect { subject }.not_to change { project.pipelines.count }
end
2017-08-17 22:00:37 +05:30
end
end
2017-09-10 17:25:29 +05:30
context 'when the schedule is not runnable by the user' do
it 'deactivates the schedule' do
subject
expect(pipeline_schedule.reload.active).to be_falsy
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
it 'does not schedule a pipeline' do
2017-08-17 22:00:37 +05:30
expect { subject }.not_to change { project.pipelines.count }
end
end
end