diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-13 17:14:40 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-02-13 17:14:40 +0300 |
commit | 19ef4083f373dd5fdc6b4c59325a4cb14179e699 (patch) | |
tree | 281a0820d22651199b8e7aba6792d13fd3b98178 /spec/services/ci/retry_pipeline_service_spec.rb | |
parent | 1be454e71272f1a6489883e9d4b27c40c6277591 (diff) |
Add a separate CI/CD pipeline retry service class
Diffstat (limited to 'spec/services/ci/retry_pipeline_service_spec.rb')
-rw-r--r-- | spec/services/ci/retry_pipeline_service_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/services/ci/retry_pipeline_service_spec.rb b/spec/services/ci/retry_pipeline_service_spec.rb new file mode 100644 index 00000000000..6fc1d884920 --- /dev/null +++ b/spec/services/ci/retry_pipeline_service_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Ci::RetryPipelineService, '#execute', :services do + let(:user) { create(:user) } + let(:project) { create(:empty_project) } + let(:pipeline) { create(:ci_pipeline, project: project) } + let(:service) { described_class.new(pipeline, user) } + + context 'when user has ability to modify pipeline' do + let(:user) { create(:admin) } + + context 'when there are failed builds in the last stage' do + before do + create_build(name: 'rspec 1', status: :success, stage_num: 0) + create_build(name: 'rspec 2', status: :failed, stage_num: 1) + create_build(name: 'rspec 3', status: :canceled, stage_num: 1) + end + + it 'enqueues all builds in the last stage' do + service.execute + + expect(build('rspec 2')).to be_pending + expect(build('rspec 3')).to be_pending + end + end + end + + context 'when user is not allowed to retry pipeline' do + it 'raises an error' do + expect { service.execute } + .to raise_error Gitlab::Access::AccessDeniedError + end + end + + def build(name) + pipeline.statuses.find_by(name: name) + end + + def create_build(name:, status:, stage_num:) + create(:ci_build, name: name, + status: status, + stage: "stage_#{stage_num}", + stage_idx: stage_num, + pipeline: pipeline) do |build| + pipeline.update_status + end + end +end |