diff options
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/ci/pipelines_for_merge_request_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/group_labels_finder_spec.rb | 42 | ||||
-rw-r--r-- | spec/finders/groups_finder_spec.rb | 56 | ||||
-rw-r--r-- | spec/finders/merge_requests/by_approvals_finder_spec.rb | 82 | ||||
-rw-r--r-- | spec/finders/packages/generic/package_finder_spec.rb | 31 |
5 files changed, 170 insertions, 43 deletions
diff --git a/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb b/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb index 196fde5efe0..65f6dc0ba74 100644 --- a/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb +++ b/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb @@ -122,7 +122,7 @@ RSpec.describe Ci::PipelinesForMergeRequestFinder do end context 'with unsaved merge request' do - let(:merge_request) { build(:merge_request) } + let(:merge_request) { build(:merge_request, source_project: create(:project, :repository)) } let!(:pipeline) do create(:ci_empty_pipeline, project: project, diff --git a/spec/finders/group_labels_finder_spec.rb b/spec/finders/group_labels_finder_spec.rb deleted file mode 100644 index d65a8fb4fed..00000000000 --- a/spec/finders/group_labels_finder_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe GroupLabelsFinder, '#execute' do - let!(:group) { create(:group) } - let!(:user) { create(:user) } - let!(:label1) { create(:group_label, title: 'Foo', description: 'Lorem ipsum', group: group) } - let!(:label2) { create(:group_label, title: 'Bar', description: 'Fusce consequat', group: group) } - - it 'returns all group labels sorted by name if no params' do - result = described_class.new(user, group).execute - - expect(result.to_a).to match_array([label2, label1]) - end - - it 'returns all group labels sorted by name desc' do - result = described_class.new(user, group, sort: 'name_desc').execute - - expect(result.to_a).to match_array([label2, label1]) - end - - it 'returns group labels that match search' do - result = described_class.new(user, group, search: 'Foo').execute - - expect(result.to_a).to match_array([label1]) - end - - it 'returns group labels user subscribed to' do - label2.subscribe(user) - - result = described_class.new(user, group, subscribed: 'true').execute - - expect(result.to_a).to match_array([label2]) - end - - it 'returns second page of labels' do - result = described_class.new(user, group, page: '2').execute - - expect(result.to_a).to match_array([]) - end -end diff --git a/spec/finders/groups_finder_spec.rb b/spec/finders/groups_finder_spec.rb index 48e4c5dadc9..c9e9328794e 100644 --- a/spec/finders/groups_finder_spec.rb +++ b/spec/finders/groups_finder_spec.rb @@ -161,5 +161,61 @@ RSpec.describe GroupsFinder do end end end + + context 'with include parent group descendants' do + let_it_be(:user) { create(:user) } + let_it_be(:parent_group) { create(:group, :public) } + let_it_be(:public_subgroup) { create(:group, :public, parent: parent_group) } + let_it_be(:internal_sub_subgroup) { create(:group, :internal, parent: public_subgroup) } + let_it_be(:private_sub_subgroup) { create(:group, :private, parent: public_subgroup) } + let_it_be(:public_sub_subgroup) { create(:group, :public, parent: public_subgroup) } + let(:params) { { include_parent_descendants: true, parent: parent_group } } + + context 'with nil parent' do + it 'returns all accessible groups' do + params[:parent] = nil + expect(described_class.new(user, params).execute).to contain_exactly( + parent_group, + public_subgroup, + internal_sub_subgroup, + public_sub_subgroup + ) + end + end + + context 'without a user' do + it 'only returns the group public descendants' do + expect(described_class.new(nil, params).execute).to contain_exactly( + public_subgroup, + public_sub_subgroup + ) + end + end + + context 'when a user is present' do + it 'returns the group public and internal descendants' do + expect(described_class.new(user, params).execute).to contain_exactly( + public_subgroup, + public_sub_subgroup, + internal_sub_subgroup + ) + end + end + + context 'when a parent group member is present' do + before do + parent_group.add_developer(user) + end + + it 'returns all group descendants' do + expect(described_class.new(user, params).execute).to contain_exactly( + public_subgroup, + public_sub_subgroup, + internal_sub_subgroup, + private_sub_subgroup + ) + end + end + end end end 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 diff --git a/spec/finders/packages/generic/package_finder_spec.rb b/spec/finders/packages/generic/package_finder_spec.rb new file mode 100644 index 00000000000..ed34268e7a9 --- /dev/null +++ b/spec/finders/packages/generic/package_finder_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Packages::Generic::PackageFinder do + let_it_be(:project) { create(:project) } + let_it_be(:package) { create(:generic_package, project: project) } + + describe '#execute!' do + subject(:finder) { described_class.new(project) } + + it 'finds package by name and version' do + found_package = finder.execute!(package.name, package.version) + + expect(found_package).to eq(package) + end + + it 'ignores packages with same name but different version' do + create(:generic_package, project: project, name: package.name, version: '3.1.4') + + found_package = finder.execute!(package.name, package.version) + + expect(found_package).to eq(package) + end + + it 'raises ActiveRecord::RecordNotFound if package is not found' do + expect { finder.execute!(package.name, '3.1.4') } + .to raise_error(ActiveRecord::RecordNotFound) + end + end +end |