diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-04-12 15:50:19 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-04-12 15:50:19 +0530 |
commit | 91034af3c998ce4a4f83281525304e8c50add384 (patch) | |
tree | 4cf4f4bdd32d91f4c3049596d5213b73a4235153 /spec | |
parent | 5d88de092f37497d9c08878954b099c425376bda (diff) | |
download | gitlab-ce-91034af3c998ce4a4f83281525304e8c50add384.tar.gz |
Augment the tests for `Issue#related_branches`
- Test the case where we have a referenced merge request that's being
- excluded as a "related branch"
- This took a while to figure out, especially the
`create_cross_references!` line.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/issue_spec.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index f33b705810e..8cacce6a7bf 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -191,11 +191,27 @@ describe Issue, models: true do end describe '#related_branches' do - it "selects the right branches" do - user = build(:user) + let(:user) { build(:user, :admin) } + let(:merge_request) { create(:merge_request, description: "Closes ##{subject.iid}", + source_project: subject.project, source_branch: "branch-#{subject.iid}") } + + before(:each) do allow(subject.project.repository).to receive(:branch_names). - and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name]) + and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name, "branch-#{subject.iid}"]) + + # Without this stub, the `create(:merge_request)` above fails because it can't find + # the source branch. This seems like a reasonable compromise, in comparison with + # setting up a full repo here. + allow_any_instance_of(MergeRequest).to receive(:create_merge_request_diff) + end + + it "selects the right branches when there are no referenced merge requests" do + expect(subject.related_branches(user)).to eq([subject.to_branch_name, "branch-#{subject.iid}"]) + end + it "selects the right branches when there is a referenced merge request" do + merge_request.create_cross_references!(user) + expect(subject.referenced_merge_requests).to_not be_empty expect(subject.related_branches(user)).to eq([subject.to_branch_name]) end end |