debian-mirror-gitlab/spec/services/merge_requests/after_create_service_spec.rb

98 lines
2.8 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe MergeRequests::AfterCreateService do
2020-04-08 14:13:33 +05:30
let_it_be(:merge_request) { create(:merge_request) }
subject(:after_create_service) do
described_class.new(merge_request.target_project, merge_request.author)
end
describe '#execute' do
let(:event_service) { instance_double('EventCreateService', open_mr: true) }
let(:notification_service) { instance_double('NotificationService', new_merge_request: true) }
before do
allow(after_create_service).to receive(:event_service).and_return(event_service)
allow(after_create_service).to receive(:notification_service).and_return(notification_service)
end
2021-02-22 17:27:13 +05:30
subject(:execute_service) { after_create_service.execute(merge_request) }
2020-04-08 14:13:33 +05:30
it 'creates a merge request open event' do
expect(event_service)
.to receive(:open_mr).with(merge_request, merge_request.author)
2021-02-22 17:27:13 +05:30
execute_service
2020-04-08 14:13:33 +05:30
end
2021-03-08 18:12:59 +05:30
it 'calls the merge request activity counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_create_mr_action)
.with(user: merge_request.author)
2021-04-17 20:07:23 +05:30
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_mr_including_ci_config)
.with(user: merge_request.author, merge_request: merge_request)
2021-03-08 18:12:59 +05:30
execute_service
end
2020-04-08 14:13:33 +05:30
it 'creates a new merge request notification' do
expect(notification_service)
.to receive(:new_merge_request).with(merge_request, merge_request.author)
2021-02-22 17:27:13 +05:30
execute_service
2020-04-08 14:13:33 +05:30
end
it 'writes diffs to the cache' do
expect(merge_request)
.to receive_message_chain(:diffs, :write_cache)
2021-02-22 17:27:13 +05:30
execute_service
2020-04-08 14:13:33 +05:30
end
it 'creates cross references' do
expect(merge_request)
.to receive(:create_cross_references!).with(merge_request.author)
2021-02-22 17:27:13 +05:30
execute_service
2020-04-08 14:13:33 +05:30
end
it 'creates a pipeline and updates the HEAD pipeline' do
expect(after_create_service)
.to receive(:create_pipeline_for).with(merge_request, merge_request.author)
expect(merge_request).to receive(:update_head_pipeline)
2021-02-22 17:27:13 +05:30
execute_service
end
2021-03-11 19:13:27 +05:30
it_behaves_like 'records an onboarding progress action', :merge_request_created do
let(:namespace) { merge_request.target_project.namespace }
2020-04-08 14:13:33 +05:30
end
2021-04-17 20:07:23 +05:30
context 'when merge request is in unchecked state' do
before do
merge_request.mark_as_unchecked!
execute_service
end
it 'does not change its state' do
expect(merge_request.reload).to be_unchecked
end
end
context 'when merge request is in preparing state' do
before do
merge_request.mark_as_preparing!
execute_service
end
it 'marks the merge request as unchecked' do
expect(merge_request.reload).to be_unchecked
end
end
2020-04-08 14:13:33 +05:30
end
end