gitlab-org--gitlab-foss/spec/services/ci/destroy_pipeline_service_spec.rb
Stan Hu 05f30ac6bb Disable audit event logging for pipeline destruction
AuditEventService isn't equipped to handle logging of the destruction of
entities such as CI pipelines. It's a project-level event that operates
on a pipeline. The current log doesn't even indicate that the pipeline
is being destroyed.

This is a CE backport of
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/9105.  We're
removing the auditing call because it breaks the EE implementation.
2019-01-10 01:30:41 -08:00

60 lines
1.5 KiB
Ruby

# 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 'does not log an audit event' do
expect { subject }.not_to change { SecurityEvent.count }
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