diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /spec/services/events | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'spec/services/events')
-rw-r--r-- | spec/services/events/destroy_service_spec.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/services/events/destroy_service_spec.rb b/spec/services/events/destroy_service_spec.rb new file mode 100644 index 00000000000..8dcbb83eb1d --- /dev/null +++ b/spec/services/events/destroy_service_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Events::DestroyService do + subject(:service) { described_class.new(project) } + + let_it_be(:project, reload: true) { create(:project, :repository) } + let_it_be(:another_project) { create(:project) } + let_it_be(:merge_request) { create(:merge_request, source_project: project) } + let_it_be(:user) { create(:user) } + + let!(:unrelated_event) { create(:event, :merged, project: another_project, target: another_project, author: user) } + + before do + create(:event, :created, project: project, target: project, author: user) + create(:event, :created, project: project, target: merge_request, author: user) + create(:event, :merged, project: project, target: merge_request, author: user) + end + + let(:events) { project.events } + + describe '#execute', :aggregate_failures do + it 'deletes the events' do + response = nil + + expect { response = subject.execute }.to change(Event, :count).by(-3) + + expect(response).to be_success + expect(unrelated_event.reload).to be_present + end + + context 'when an error is raised while deleting the records' do + before do + allow(project).to receive_message_chain(:events, :all, :delete_all).and_raise(ActiveRecord::ActiveRecordError) + end + + it 'returns error' do + response = subject.execute + + expect(response).to be_error + expect(response.message).to eq 'Failed to remove events.' + end + + it 'does not delete events' do + expect { subject.execute }.not_to change(Event, :count) + end + end + end +end |