Commit 7d38a023 authored by Christian Couder's avatar Christian Couder

Add test for 'assign' push option

parent d67bbfdc
......@@ -25,6 +25,10 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
let(:default_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{project.default_branch}" }
let(:error_mr_required) { "A merge_request.create push option is required to create a merge request for branch #{source_branch}" }
before do
stub_licensed_features(multiple_merge_request_assignees: false)
end
shared_examples_for 'a service that can create a merge request' do
subject(:last_mr) { MergeRequest.last }
......@@ -117,6 +121,17 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
end
end
# In the foss version of GitLab, there can be only one assignee
shared_examples_for 'a service that can change one assignee of a merge request' do
subject(:last_mr) { MergeRequest.last }
it 'changes assignee count' do
service.execute
expect(last_mr.assignees.count).to eq(1)
end
end
shared_examples_for 'a service that does not create a merge request' do
it do
expect { service.execute }.not_to change { MergeRequest.count }
......@@ -603,6 +618,68 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
end
end
describe '`assign` push option' do
let(:push_options) { { assign: { user2.id => 1, user3.id => 1 } } }
context 'with a new branch' do
let(:changes) { new_branch_changes }
it_behaves_like 'a service that does not create a merge request'
it 'adds an error to the service' do
service.execute
expect(service.errors).to include(error_mr_required)
end
context 'when coupled with the `create` push option in foss' do
let(:push_options) { { create: true, assign: { user2.id => 1, user3.id => 1 } } }
it_behaves_like 'a service that can create a merge request'
it_behaves_like 'a service that can change one assignee of a merge request'
end
end
context 'with an existing branch but no open MR' do
let(:changes) { existing_branch_changes }
it_behaves_like 'a service that does not create a merge request'
it 'adds an error to the service' do
service.execute
expect(service.errors).to include(error_mr_required)
end
context 'when coupled with the `create` push option in foss' do
let(:push_options) { { create: true, assign: { user2.id => 1, user3.id => 1 } } }
it_behaves_like 'a service that can create a merge request'
it_behaves_like 'a service that can change one assignee of a merge request'
end
end
context 'with an existing branch that has a merge request open in foss' do
let(:changes) { existing_branch_changes }
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)}
it_behaves_like 'a service that does not create a merge request'
it_behaves_like 'a service that can change one assignee of a merge request'
end
context 'with a deleted branch' do
let(:changes) { deleted_branch_changes }
it_behaves_like 'a service that does nothing'
end
context 'with the project default branch' do
let(:changes) { default_branch_changes }
it_behaves_like 'a service that does nothing'
end
end
describe 'multiple pushed branches' do
let(:push_options) { { create: true } }
let(:changes) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment