summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2019-03-07 11:27:52 +0000
committerDouwe Maan <douwe@gitlab.com>2019-03-07 11:27:52 +0000
commitc45bb62c0ae36018891a343c7c820fc1a901e33e (patch)
treef5a9cb739ab4ed509d66947bbf9581906310e271 /spec/services
parente571cbaa2f0b5096e514bc96fbc8f26909d8e52b (diff)
parent2cb45dd0d56156ace389239088822c428d87585c (diff)
downloadgitlab-ce-c45bb62c0ae36018891a343c7c820fc1a901e33e.tar.gz
Merge branch 'osw-merge-to-ref-changes-for-ci-team' into 'master'
Make merge to refs/merge-requests/:iid/merge not raise when FF-only enabled Closes #58393 See merge request gitlab-org/gitlab-ce!25653
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/merge_requests/merge_to_ref_service_spec.rb96
1 files changed, 45 insertions, 51 deletions
diff --git a/spec/services/merge_requests/merge_to_ref_service_spec.rb b/spec/services/merge_requests/merge_to_ref_service_spec.rb
index 96f2fde7117..fabca8f6b4a 100644
--- a/spec/services/merge_requests/merge_to_ref_service_spec.rb
+++ b/spec/services/merge_requests/merge_to_ref_service_spec.rb
@@ -19,27 +19,7 @@ describe MergeRequests::MergeToRefService do
end
end
- set(:user) { create(:user) }
- let(:merge_request) { create(:merge_request, :simple) }
- let(:project) { merge_request.project }
-
- before do
- project.add_maintainer(user)
- end
-
- describe '#execute' do
- let(:service) do
- described_class.new(project, user,
- commit_message: 'Awesome message',
- 'should_remove_source_branch' => true)
- end
-
- def process_merge_to_ref
- perform_enqueued_jobs do
- service.execute(merge_request)
- end
- end
-
+ shared_examples_for 'successfully merges to ref with merge method' do
it 'writes commit to merge ref' do
repository = project.repository
target_ref = merge_request.merge_ref_path
@@ -52,9 +32,31 @@ describe MergeRequests::MergeToRefService do
expect(result[:status]).to eq(:success)
expect(result[:commit_id]).to be_present
+ expect(result[:source_id]).to eq(merge_request.source_branch_sha)
+ expect(result[:target_id]).to eq(merge_request.target_branch_sha)
expect(repository.ref_exists?(target_ref)).to be(true)
expect(ref_head.id).to eq(result[:commit_id])
end
+ end
+
+ shared_examples_for 'successfully evaluates pre-condition checks' do
+ it 'returns error when feature is disabled' do
+ stub_feature_flags(merge_to_tmp_merge_ref_path: false)
+
+ result = service.execute(merge_request)
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq('Feature is not enabled')
+ end
+
+ it 'returns an error when the failing to process the merge' do
+ allow(project.repository).to receive(:merge_to_ref).and_return(nil)
+
+ result = service.execute(merge_request)
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq('Conflicts detected during merge')
+ end
it 'does not send any mail' do
expect { process_merge_to_ref }.not_to change { ActionMailer::Base.deliveries.count }
@@ -73,25 +75,31 @@ describe MergeRequests::MergeToRefService do
process_merge_to_ref
end
+ end
- it 'returns error when feature is disabled' do
- stub_feature_flags(merge_to_tmp_merge_ref_path: false)
+ set(:user) { create(:user) }
+ let(:merge_request) { create(:merge_request, :simple) }
+ let(:project) { merge_request.project }
- result = service.execute(merge_request)
+ before do
+ project.add_maintainer(user)
+ end
- expect(result[:status]).to eq(:error)
- expect(result[:message]).to eq('Feature is not enabled')
+ describe '#execute' do
+ let(:service) do
+ described_class.new(project, user, commit_message: 'Awesome message',
+ should_remove_source_branch: true)
end
- it 'returns an error when the failing to process the merge' do
- allow(project.repository).to receive(:merge_to_ref).and_return(nil)
-
- result = service.execute(merge_request)
-
- expect(result[:status]).to eq(:error)
- expect(result[:message]).to eq('Conflicts detected during merge')
+ def process_merge_to_ref
+ perform_enqueued_jobs do
+ service.execute(merge_request)
+ end
end
+ it_behaves_like 'successfully merges to ref with merge method'
+ it_behaves_like 'successfully evaluates pre-condition checks'
+
context 'commit history comparison with regular MergeService' do
let(:merge_ref_service) do
described_class.new(project, user, {})
@@ -122,29 +130,15 @@ describe MergeRequests::MergeToRefService do
context 'when semi-linear merge method' do
let(:merge_method) { :rebase_merge }
- it 'return error when MR should be able to fast-forward' do
- allow(merge_request).to receive(:should_be_rebased?) { true }
-
- error_message = 'Fast-forward merge is not possible. Please update your source branch.'
-
- result = service.execute(merge_request)
-
- expect(result[:status]).to eq(:error)
- expect(result[:message]).to eq(error_message)
- end
+ it_behaves_like 'successfully merges to ref with merge method'
+ it_behaves_like 'successfully evaluates pre-condition checks'
end
context 'when fast-forward merge method' do
let(:merge_method) { :ff }
- it 'returns error' do
- error_message = "Fast-forward to #{merge_request.merge_ref_path} is currently not supported."
-
- result = service.execute(merge_request)
-
- expect(result[:status]).to eq(:error)
- expect(result[:message]).to eq(error_message)
- end
+ it_behaves_like 'successfully merges to ref with merge method'
+ it_behaves_like 'successfully evaluates pre-condition checks'
end
context 'when MR is not mergeable to ref' do