diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/services/merge_requests/push_options_handler_service_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/services/merge_requests/push_options_handler_service_spec.rb')
-rw-r--r-- | spec/services/merge_requests/push_options_handler_service_spec.rb | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb index 348ea9ad7d4..338057f23d5 100644 --- a/spec/services/merge_requests/push_options_handler_service_spec.rb +++ b/spec/services/merge_requests/push_options_handler_service_spec.rb @@ -20,7 +20,17 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do let(:source_branch) { 'fix' } let(:target_branch) { 'feature' } let(:title) { 'my title' } + let(:draft_title) { 'Draft: my title' } + let(:draft) { true } let(:description) { 'my description' } + let(:multiline_description) do + <<~MD.chomp + Line 1 + Line 2 + Line 3 + MD + end + let(:label1) { 'mylabel1' } let(:label2) { 'mylabel2' } let(:label3) { 'mylabel3' } @@ -64,6 +74,26 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do end end + shared_examples_for 'a service that can set the multiline description of a merge request' do + subject(:last_mr) { MergeRequest.last } + + it 'sets the multiline description' do + service.execute + + expect(last_mr.description).to eq(multiline_description) + end + end + + shared_examples_for 'a service that can set the draft of a merge request' do + subject(:last_mr) { MergeRequest.last } + + it 'sets the draft' do + service.execute + + expect(last_mr.draft).to eq(draft) + end + end + shared_examples_for 'a service that can set the milestone of a merge request' do subject(:last_mr) { MergeRequest.last } @@ -417,6 +447,74 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do it_behaves_like 'a service that does not create a merge request' it_behaves_like 'a service that can set the description of a merge request' + + context 'with a multiline description' do + let(:push_options) { { description: "Line 1\\nLine 2\\nLine 3" } } + + it_behaves_like 'a service that does not create a merge request' + it_behaves_like 'a service that can set the multiline description of a merge request' + end + end + + it_behaves_like 'with a deleted branch' + it_behaves_like 'with the project default branch' + end + + describe '`draft` push option' do + let(:push_options) { { draft: draft } } + + 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' do + let(:push_options) { { create: true, draft: draft } } + + it_behaves_like 'a service that can create a merge request' + it_behaves_like 'a service that can set the draft 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' do + let(:push_options) { { create: true, draft: draft } } + + it_behaves_like 'a service that can create a merge request' + it_behaves_like 'a service that can set the draft of a merge request' + end + end + + context 'with an existing branch that has a merge request open' 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 set the draft of a merge request' + end + + context 'draft title provided while `draft` push option is set to false' do + let(:push_options) { { create: true, draft: false, title: draft_title } } + let(:changes) { new_branch_changes } + + it_behaves_like 'a service that can create a merge request' + it_behaves_like 'a service that can set the draft of a merge request' end it_behaves_like 'with a deleted branch' |