diff options
author | micael.bergeron <micaelbergeron@gmail.com> | 2017-10-11 16:06:15 -0400 |
---|---|---|
committer | micael.bergeron <micaelbergeron@gmail.com> | 2017-10-11 16:41:36 -0400 |
commit | 845b2f1abe408da48441d1fd271705684f15b114 (patch) | |
tree | 497a695bac457a23cfb21e10e3b3ab8a9be6c4eb | |
parent | 5a2acfe036b4ce2c74b015101c57f040b851899c (diff) | |
download | gitlab-ce-845b2f1abe408da48441d1fd271705684f15b114.tar.gz |
add spec
-rw-r--r-- | spec/factories/merge_requests.rb | 6 | ||||
-rw-r--r-- | spec/services/merge_requests/merge_service_spec.rb | 23 |
2 files changed, 22 insertions, 7 deletions
diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 2c732aaf4ed..7c4a22c94c2 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -73,6 +73,12 @@ FactoryGirl.define do merge_user author end + trait :remove_source_branch do + merge_params do + { 'force_remove_source_branch' => '1' } + end + end + after(:build) do |merge_request| target_project = merge_request.target_project source_project = merge_request.source_project diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index 80213d093f1..d1043f99b5a 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -185,7 +185,7 @@ describe MergeRequests::MergeService do context 'source branch removal' do context 'when the source branch is protected' do let(:service) do - described_class.new(project, user, should_remove_source_branch: '1') + described_class.new(project, user, 'should_remove_source_branch' => true) end before do @@ -200,7 +200,7 @@ describe MergeRequests::MergeService do context 'when the source branch is the default branch' do let(:service) do - described_class.new(project, user, should_remove_source_branch: '1') + described_class.new(project, user, 'should_remove_source_branch' => true) end before do @@ -215,10 +215,10 @@ describe MergeRequests::MergeService do context 'when the source branch can be removed' do context 'when MR author set the source branch to be removed' do - let(:service) do - merge_request.merge_params['force_remove_source_branch'] = '1' - merge_request.save! - described_class.new(project, user, commit_message: 'Awesome message') + let(:service) { described_class.new(project, user, commit_message: 'Awesome message') } + + before do + merge_request.update_attribute(:merge_params, { 'force_remove_source_branch' => '1' }) end it 'removes the source branch using the author user' do @@ -227,11 +227,20 @@ describe MergeRequests::MergeService do .and_call_original service.execute(merge_request) end + + context 'when the merger set the source branch not to be removed' do + let(:service) { described_class.new(project, user, commit_message: 'Awesome message', 'should_remove_source_branch' => false) } + + it 'does not delete the source branch' do + expect(DeleteBranchService).not_to receive(:new) + service.execute(merge_request) + end + end end context 'when MR merger set the source branch to be removed' do let(:service) do - described_class.new(project, user, commit_message: 'Awesome message', should_remove_source_branch: '1') + described_class.new(project, user, commit_message: 'Awesome message', 'should_remove_source_branch' => true) end it 'removes the source branch using the current user' do |