diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-10-05 17:40:57 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-10-05 17:40:57 +0000 |
commit | 58a256ad0bfa10211479b2685ed2d5e19948e059 (patch) | |
tree | 7078c2506e50829e1c85d43bc71deae907c29b57 /spec | |
parent | b407061a281607e0c4bf22d2b7e94a068768ccac (diff) | |
parent | 0ae48e068794a732f728de76ffbf3f95e702ba9a (diff) | |
download | gitlab-ce-58a256ad0bfa10211479b2685ed2d5e19948e059.tar.gz |
Merge branch 'issue_43097' into 'master'
Move related branches to service
Closes #43097
See merge request gitlab-org/gitlab-ce!22094
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/issue_spec.rb | 39 | ||||
-rw-r--r-- | spec/services/issues/related_branches_service_spec.rb | 39 |
2 files changed, 39 insertions, 39 deletions
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 19bc2713ef5..6f900a60213 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -268,45 +268,6 @@ describe Issue do end end - describe '#related_branches' do - let(:user) { create(:admin) } - - before do - allow(subject.project.repository).to receive(:branch_names) - .and_return(["mpempe", "#{subject.iid}mepmep", subject.to_branch_name, "#{subject.iid}-branch"]) - - # 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, "#{subject.iid}-branch"]) - end - - it "selects the right branches when there is a referenced merge request" do - merge_request = create(:merge_request, { description: "Closes ##{subject.iid}", - source_project: subject.project, - source_branch: "#{subject.iid}-branch" }) - merge_request.create_cross_references!(user) - - referenced_merge_requests = Issues::ReferencedMergeRequestsService - .new(subject.project, user) - .referenced_merge_requests(subject) - - expect(referenced_merge_requests).not_to be_empty - expect(subject.related_branches(user)).to eq([subject.to_branch_name]) - end - - it 'excludes stable branches from the related branches' do - allow(subject.project.repository).to receive(:branch_names) - .and_return(["#{subject.iid}-0-stable"]) - - expect(subject.related_branches(user)).to eq [] - end - end - describe '#suggested_branch_name' do let(:repository) { double } diff --git a/spec/services/issues/related_branches_service_spec.rb b/spec/services/issues/related_branches_service_spec.rb new file mode 100644 index 00000000000..c2e1eba6a63 --- /dev/null +++ b/spec/services/issues/related_branches_service_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe Issues::RelatedBranchesService do + let(:user) { create(:admin) } + let(:issue) { create(:issue) } + + subject { described_class.new(issue.project, user) } + + describe '#execute' do + before do + allow(issue.project.repository).to receive(:branch_names).and_return(["mpempe", "#{issue.iid}mepmep", issue.to_branch_name, "#{issue.iid}-branch"]) + end + + it "selects the right branches when there are no referenced merge requests" do + expect(subject.execute(issue)).to eq([issue.to_branch_name, "#{issue.iid}-branch"]) + end + + it "selects the right branches when there is a referenced merge request" do + merge_request = create(:merge_request, { description: "Closes ##{issue.iid}", + source_project: issue.project, + source_branch: "#{issue.iid}-branch" }) + merge_request.create_cross_references!(user) + + referenced_merge_requests = Issues::ReferencedMergeRequestsService + .new(issue.project, user) + .referenced_merge_requests(issue) + + expect(referenced_merge_requests).not_to be_empty + expect(subject.execute(issue)).to eq([issue.to_branch_name]) + end + + it 'excludes stable branches from the related branches' do + allow(issue.project.repository).to receive(:branch_names) + .and_return(["#{issue.iid}-0-stable"]) + + expect(subject.execute(issue)).to eq [] + end + end +end |