2017-05-07 18:35:56 -04:00
|
|
|
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-05-10 04:04:25 -04:00
|
|
|
pipeline_schedule.update_column(:next_run_at, 1.day.ago)
|
|
|
|
end
|
2017-05-07 18:35:56 -04:00
|
|
|
|
2017-05-10 04:04:25 -04:00
|
|
|
context 'when the schedule is runnable by the user' do
|
2017-05-07 18:35:56 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|
|
|
|
|
2017-05-10 04:04:25 -04:00
|
|
|
context 'when there is a scheduled pipeline within next_run_at' do
|
2017-11-20 04:29:59 -05:00
|
|
|
shared_examples 'successful scheduling' do
|
|
|
|
it 'creates a new pipeline' do
|
|
|
|
expect { subject }.to change { project.pipelines.count }.by(1)
|
2017-11-22 12:55:10 -05:00
|
|
|
expect(Ci::Pipeline.last).to be_schedule
|
2017-11-20 04:29:59 -05:00
|
|
|
|
|
|
|
pipeline_schedule.reload
|
|
|
|
expect(pipeline_schedule.next_run_at).to be > Time.now
|
|
|
|
expect(pipeline_schedule).to eq(project.pipelines.last.pipeline_schedule)
|
|
|
|
expect(pipeline_schedule).to be_active
|
|
|
|
end
|
2017-05-10 04:04:25 -04:00
|
|
|
end
|
2017-05-07 18:35:56 -04:00
|
|
|
|
2017-11-20 04:29:59 -05:00
|
|
|
it_behaves_like 'successful scheduling'
|
2017-05-10 04:04:25 -04:00
|
|
|
|
2017-11-20 04:29:59 -05:00
|
|
|
context 'when the latest commit contains [ci skip]' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Ci::Pipeline)
|
|
|
|
.to receive(:git_commit_message)
|
|
|
|
.and_return('some commit [ci skip]')
|
|
|
|
end
|
2017-05-10 04:04:25 -04:00
|
|
|
|
2017-11-20 04:29:59 -05:00
|
|
|
it_behaves_like 'successful scheduling'
|
2017-05-10 04:04:25 -04:00
|
|
|
end
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|
|
|
|
|
2017-11-20 04:29:59 -05:00
|
|
|
context 'when the schedule is deactivated' do
|
2017-05-10 04:04:25 -04:00
|
|
|
before do
|
|
|
|
pipeline_schedule.deactivate!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not creates a new pipeline' do
|
|
|
|
expect { subject }.not_to change { project.pipelines.count }
|
|
|
|
end
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-10 04:04:25 -04:00
|
|
|
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-05-07 18:35:56 -04:00
|
|
|
end
|
|
|
|
|
2017-05-10 04:04:25 -04:00
|
|
|
it 'does not schedule a pipeline' do
|
2017-05-07 18:35:56 -04:00
|
|
|
expect { subject }.not_to change { project.pipelines.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|