diff options
author | Felipe Artur <felipefac@gmail.com> | 2018-10-03 23:45:39 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2018-10-04 21:59:14 +0300 |
commit | 0ae48e068794a732f728de76ffbf3f95e702ba9a (patch) | |
tree | e63047572f6dfc7533af377f7329dd242b7f396d /spec/services/issues | |
parent | 8a8ae2f57fe0db9b33f100e9a68c9eac4fd71c4d (diff) |
Move issue related_branches to service
Moves the related_branches method from Issue model
to RelatedBranchesService
Diffstat (limited to 'spec/services/issues')
-rw-r--r-- | spec/services/issues/related_branches_service_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
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 |