debian-mirror-gitlab/spec/services/ci/destroy_pipeline_service_spec.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe ::Ci::DestroyPipelineService do
2019-05-30 16:15:17 +05:30
let(:project) { create(:project) }
let!(:pipeline) { create(:ci_pipeline, project: project) }
2019-02-15 15:39:39 +05:30
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
2019-03-02 22:35:43 +05:30
it 'does not log an audit event' do
expect { subject }.not_to change { SecurityEvent.count }
2019-02-15 15:39:39 +05:30
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 'raises an exception' do
expect { subject }.to raise_error(Gitlab::Access::AccessDeniedError)
end
end
end