summaryrefslogtreecommitdiff
path: root/spec/services/merge_requests/build_service_spec.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-11-28 18:01:09 +0000
committerRémy Coutable <remy@rymai.me>2017-11-28 18:01:09 +0000
commitbecf29e3ab3463a8a1f3c6ed7bbfd7d2dcc49ea0 (patch)
treea56172dc723850b3baf3452a575bb77c461dbe64 /spec/services/merge_requests/build_service_spec.rb
parent2081650afc6417daa5933146c0922ff622a958b7 (diff)
parent3c6a4d63636ba41dad0ce63cf536761fc3b5ef64 (diff)
downloadgitlab-ce-becf29e3ab3463a8a1f3c6ed7bbfd7d2dcc49ea0.tar.gz
Merge branch '40530-merge-request-generates-wrong-diff-when-branch-and-tag-have-the-same-name' into 'master'
Resolve "Merge request generates wrong diff when branch and tag have the same name" Closes #40530 See merge request gitlab-org/gitlab-ce!15591
Diffstat (limited to 'spec/services/merge_requests/build_service_spec.rb')
-rw-r--r--spec/services/merge_requests/build_service_spec.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/spec/services/merge_requests/build_service_spec.rb b/spec/services/merge_requests/build_service_spec.rb
index b46c419de14..fee293760f5 100644
--- a/spec/services/merge_requests/build_service_spec.rb
+++ b/spec/services/merge_requests/build_service_spec.rb
@@ -29,13 +29,27 @@ describe MergeRequests::BuildService do
before do
project.team << [user, :guest]
+ end
+ def stub_compare
allow(CompareService).to receive_message_chain(:new, :execute).and_return(compare)
allow(project).to receive(:commit).and_return(commit_1)
allow(project).to receive(:commit).and_return(commit_2)
end
- describe 'execute' do
+ describe '#execute' do
+ it 'calls the compare service with the correct arguments' do
+ expect(CompareService).to receive(:new)
+ .with(project, Gitlab::Git::BRANCH_REF_PREFIX + source_branch)
+ .and_call_original
+
+ expect_any_instance_of(CompareService).to receive(:execute)
+ .with(project, Gitlab::Git::BRANCH_REF_PREFIX + target_branch)
+ .and_call_original
+
+ merge_request
+ end
+
context 'missing source branch' do
let(:source_branch) { '' }
@@ -52,6 +66,10 @@ describe MergeRequests::BuildService do
let(:target_branch) { nil }
let(:commits) { Commit.decorate([commit_1], project) }
+ before do
+ stub_compare
+ end
+
it 'creates compare object with target branch as default branch' do
expect(merge_request.compare).to be_present
expect(merge_request.target_branch).to eq(project.default_branch)
@@ -77,6 +95,10 @@ describe MergeRequests::BuildService do
context 'no commits in the diff' do
let(:commits) { [] }
+ before do
+ stub_compare
+ end
+
it 'allows the merge request to be created' do
expect(merge_request.can_be_created).to eq(true)
end
@@ -89,6 +111,10 @@ describe MergeRequests::BuildService do
context 'one commit in the diff' do
let(:commits) { Commit.decorate([commit_1], project) }
+ before do
+ stub_compare
+ end
+
it 'allows the merge request to be created' do
expect(merge_request.can_be_created).to eq(true)
end
@@ -149,6 +175,10 @@ describe MergeRequests::BuildService do
context 'more than one commit in the diff' do
let(:commits) { Commit.decorate([commit_1, commit_2], project) }
+ before do
+ stub_compare
+ end
+
it 'allows the merge request to be created' do
expect(merge_request.can_be_created).to eq(true)
end