diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-11-12 21:18:57 +0300 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-11-12 21:43:03 +0300 |
commit | 99203bfe23975b8dbbaa5daa613fbc90fd39178f (patch) | |
tree | 77ecf8ef90762f09b85e8cf5003d5c6e080171fd /spec/services | |
parent | 5b45cd246373f18bf678dbdecad589733cfec8b0 (diff) |
Destroy pipeline in service
Move all logic for destroying a Pipeline into a service so it's easily
reusable.
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/ci/destroy_pipeline_service_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/services/ci/destroy_pipeline_service_spec.rb b/spec/services/ci/destroy_pipeline_service_spec.rb new file mode 100644 index 00000000000..9f449dd73e8 --- /dev/null +++ b/spec/services/ci/destroy_pipeline_service_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Ci::DestroyPipelineService do + let(:project) { create(:project) } + let!(:pipeline) { create(:ci_pipeline, project: project) } + + subject { described_class.new(project, user).execute(pipeline) } + + context 'user is owner' do + let(:user) { project.owner } + + it 'destroys the pipeline' do + subject + + expect { pipeline.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'logs an audit event' do + expect { subject }.to change { SecurityEvent.count }.by(1) + end + + context 'when the pipeline has jobs' do + let!(:build) { create(:ci_build, project: project, pipeline: pipeline) } + + it 'destroys associated jobs' do + subject + + expect { build.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'destroys associated stages' do + stages = pipeline.stages + + subject + + expect(stages).to all(raise_error(ActiveRecord::RecordNotFound)) + end + + context 'when job has artifacts' do + let!(:artifact) { create(:ci_job_artifact, :archive, job: build) } + + it 'destroys associated artifacts' do + subject + + expect { artifact.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end + end + + context 'user is not owner' do + let(:user) { create(:user) } + + it 'returns false' do + is_expected.to eq(false) + end + + it 'does not destroy the pipeline' do + subject + + expect { pipeline.reload }.not_to raise_error + end + end +end |