diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/finders/merge_requests_finder_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/finders/merge_requests_finder_spec.rb')
-rw-r--r-- | spec/finders/merge_requests_finder_spec.rb | 79 |
1 files changed, 64 insertions, 15 deletions
diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index b6f2c7bb992..f76110e3d85 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -2,10 +2,28 @@ require 'spec_helper' -describe MergeRequestsFinder do +RSpec.describe MergeRequestsFinder do context "multiple projects with merge requests" do include_context 'MergeRequestsFinder multiple projects with merge requests context' + shared_examples 'scalar or array parameter' do + let(:values) { merge_requests.pluck(attribute) } + let(:params) { {} } + let(:key) { attribute } + + it 'takes scalar values' do + found = described_class.new(user, params.merge(key => values.first)).execute + + expect(found).to contain_exactly(merge_requests.first) + end + + it 'takes array values' do + found = described_class.new(user, params.merge(key => values)).execute + + expect(found).to match_array(merge_requests) + end + end + describe '#execute' do it 'filters by scope' do params = { scope: 'authored', state: 'opened' } @@ -91,28 +109,56 @@ describe MergeRequestsFinder do expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request3, merge_request5) end - it 'filters by iid' do - params = { project_id: project1.id, iids: merge_request1.iid } + describe ':iid parameter' do + it_behaves_like 'scalar or array parameter' do + let(:params) { { project_id: project1.id } } + let(:merge_requests) { [merge_request1, merge_request2] } + let(:key) { :iids } + let(:attribute) { :iid } + end + end - merge_requests = described_class.new(user, params).execute + [:source_branch, :target_branch].each do |param| + describe "#{param} parameter" do + let(:merge_requests) { create_list(:merge_request, 2, :unique_branches, source_project: project4, target_project: project4, author: user) } + let(:attribute) { param } - expect(merge_requests).to contain_exactly(merge_request1) + it_behaves_like 'scalar or array parameter' + end end - it 'filters by source branch' do - params = { source_branch: merge_request2.source_branch } + describe ':label_name parameter' do + let(:common_labels) { create_list(:label, 3) } + let(:distinct_labels) { create_list(:label, 3) } + let(:merge_requests) do + common_attrs = { + source_project: project1, target_project: project1, author: user + } + distinct_labels.map do |label| + labels = [label, *common_labels] + create(:labeled_merge_request, :closed, labels: labels, **common_attrs) + end + end - merge_requests = described_class.new(user, params).execute + def find(label_name) + described_class.new(user, label_name: label_name).execute + end - expect(merge_requests).to contain_exactly(merge_request2) - end + it 'accepts a single label' do + found = find(distinct_labels.first.title) + common = find(common_labels.first.title) - it 'filters by target branch' do - params = { target_branch: merge_request2.target_branch } + expect(found).to contain_exactly(merge_requests.first) + expect(common).to match_array(merge_requests) + end - merge_requests = described_class.new(user, params).execute + it 'accepts an array of labels, all of which must match' do + all_distinct = find(distinct_labels.pluck(:title)) + all_common = find(common_labels.pluck(:title)) - expect(merge_requests).to contain_exactly(merge_request2) + expect(all_distinct).to be_empty + expect(all_common).to match_array(merge_requests) + end end it 'filters by source project id' do @@ -158,7 +204,10 @@ describe MergeRequestsFinder do merge_requests = described_class.new(user, params).execute - expect(merge_requests).to contain_exactly(merge_request1, merge_request2, merge_request3, merge_request4, merge_request5, wip_merge_request1, wip_merge_request2, wip_merge_request3, wip_merge_request4) + expect(merge_requests).to contain_exactly( + merge_request1, merge_request2, merge_request3, merge_request4, + merge_request5, wip_merge_request1, wip_merge_request2, wip_merge_request3, + wip_merge_request4) end it 'adds wip to scalar params' do |