diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/finders/merge_requests | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/finders/merge_requests')
-rw-r--r-- | spec/finders/merge_requests/by_approvals_finder_spec.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/spec/finders/merge_requests/by_approvals_finder_spec.rb b/spec/finders/merge_requests/by_approvals_finder_spec.rb new file mode 100644 index 00000000000..0e1856879f1 --- /dev/null +++ b/spec/finders/merge_requests/by_approvals_finder_spec.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MergeRequests::ByApprovalsFinder do + let_it_be(:first_user) { create(:user) } + let_it_be(:second_user) { create(:user) } + let(:third_user) { create(:user) } + + let_it_be(:merge_request_without_approvals) { create(:merge_request) } + let_it_be(:merge_request_with_first_user_approval) do + create(:merge_request).tap do |mr| + create(:approval, merge_request: mr, user: first_user) + end + end + let_it_be(:merge_request_with_both_approvals) do + create(:merge_request).tap do |mr| + create(:approval, merge_request: mr, user: first_user) + create(:approval, merge_request: mr, user: second_user) + end + end + + def merge_requests(ids: nil, names: []) + described_class.new(names, ids).execute(MergeRequest.all) + end + + context 'filter by no approvals' do + it 'returns merge requests without approvals' do + expected_result = [merge_request_without_approvals] + + expect(merge_requests(ids: 'None')).to match_array(expected_result) + expect(merge_requests(names: ['None'])).to match_array(expected_result) + end + end + + context 'filter by any approvals' do + it 'returns merge requests approved by at least one user' do + expected_result = [merge_request_with_first_user_approval, merge_request_with_both_approvals] + + expect(merge_requests(ids: 'Any')).to match_array(expected_result) + expect(merge_requests(names: ['Any'])).to match_array(expected_result) + end + end + + context 'filter by specific user approval' do + it 'returns merge requests approved by specific user' do + expected_result = [merge_request_with_first_user_approval, merge_request_with_both_approvals] + + expect(merge_requests(ids: [first_user.id])).to match_array(expected_result) + expect(merge_requests(names: [first_user.username])).to match_array(expected_result) + end + end + + context 'filter by multiple user approval' do + it 'returns merge requests approved by both users' do + expected_result = [merge_request_with_both_approvals] + + expect(merge_requests(ids: [first_user.id, second_user.id])).to match_array(expected_result) + expect(merge_requests(names: [first_user.username, second_user.username])).to match_array(expected_result) + end + + context 'limiting max conditional elements' do + it 'returns merge requests approved by both users, considering limit of 2 being defined' do + stub_const('MergeRequests::ByApprovalsFinder::MAX_FILTER_ELEMENTS', 2) + + expected_result = [merge_request_with_both_approvals] + + expect(merge_requests(ids: [first_user.id, second_user.id, third_user.id])).to match_array(expected_result) + expect(merge_requests(names: [first_user.username, second_user.username, third_user.username])).to match_array(expected_result) + end + end + end + + context 'with empty params' do + it 'returns all merge requests' do + expected_result = [merge_request_without_approvals, merge_request_with_first_user_approval, merge_request_with_both_approvals] + + expect(merge_requests(ids: [])).to match_array(expected_result) + expect(merge_requests(names: [])).to match_array(expected_result) + end + end +end |