diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/finders | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/finders')
18 files changed, 613 insertions, 192 deletions
diff --git a/spec/finders/alert_management/alerts_finder_spec.rb b/spec/finders/alert_management/alerts_finder_spec.rb index 87a5da38dd1..3a88db5d854 100644 --- a/spec/finders/alert_management/alerts_finder_spec.rb +++ b/spec/finders/alert_management/alerts_finder_spec.rb @@ -42,6 +42,12 @@ RSpec.describe AlertManagement::AlertsFinder, '#execute' do it { is_expected.to contain_exactly(resolved_alert, ignored_alert) } end + + context 'skips domain if iid is given' do + let(:params) { { iid: resolved_alert.iid, domain: 'threat_monitoring' } } + + it { is_expected.to contain_exactly(resolved_alert) } + end end context 'empty params' do diff --git a/spec/finders/ci/daily_build_group_report_results_finder_spec.rb b/spec/finders/ci/daily_build_group_report_results_finder_spec.rb index 28a732fda82..2a6e44673e3 100644 --- a/spec/finders/ci/daily_build_group_report_results_finder_spec.rb +++ b/spec/finders/ci/daily_build_group_report_results_finder_spec.rb @@ -64,13 +64,13 @@ RSpec.describe Ci::DailyBuildGroupReportResultsFinder do end end - context 'when ref_path is not present' do + context 'when ref_path query parameter is not present' do let(:ref_path) { nil } - context 'when coverages exist for the default branch' do + context 'when records with cover data from the default branch exist' do let(:default_branch) { true } - it 'returns coverage for the default branch' do + it 'returns records with default_branch:true, irrespective of ref_path' do rspec_coverage_4 = create_daily_coverage('rspec', 66.0, '2020-03-10') expect(coverages).to contain_exactly(rspec_coverage_4) 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 64b3c46e122..65f6dc0ba74 100644 --- a/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb +++ b/spec/finders/ci/pipelines_for_merge_request_finder_spec.rb @@ -225,24 +225,6 @@ RSpec.describe Ci::PipelinesForMergeRequestFinder do branch_pipeline_2, branch_pipeline]) end - - context 'when ci_pipelines_for_merge_request_finder_new_cte feature flag is disabled' do - before do - stub_feature_flags(ci_pipelines_for_merge_request_finder_new_cte: false) - end - - it 'returns only related merge request pipelines' do - expect(subject.all) - .to eq([detached_merge_request_pipeline, - branch_pipeline_2, - branch_pipeline]) - - expect(described_class.new(merge_request_2, nil).all) - .to eq([detached_merge_request_pipeline_2, - branch_pipeline_2, - branch_pipeline]) - end - end end context 'when detached merge request pipeline is run on head ref of the merge request' do diff --git a/spec/finders/cluster_ancestors_finder_spec.rb b/spec/finders/cluster_ancestors_finder_spec.rb index ea1dbea4cfe..a54809801b5 100644 --- a/spec/finders/cluster_ancestors_finder_spec.rb +++ b/spec/finders/cluster_ancestors_finder_spec.rb @@ -83,8 +83,16 @@ RSpec.describe ClusterAncestorsFinder, '#execute' do let(:clusterable) { Clusters::Instance.new } let(:user) { create(:admin) } - it 'returns the list of instance clusters' do - is_expected.to eq([instance_cluster]) + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns the list of instance clusters' do + is_expected.to eq([instance_cluster]) + end + end + + context 'when admin mode is disabled' do + it 'returns nothing' do + is_expected.to be_empty + end end end end diff --git a/spec/finders/concerns/packages/finder_helper_spec.rb b/spec/finders/concerns/packages/finder_helper_spec.rb new file mode 100644 index 00000000000..73f77647573 --- /dev/null +++ b/spec/finders/concerns/packages/finder_helper_spec.rb @@ -0,0 +1,161 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Packages::FinderHelper do + describe '#packages_visible_to_user' do + using RSpec::Parameterized::TableSyntax + + let_it_be(:user) { create(:user) } + let_it_be_with_reload(:group) { create(:group) } + let_it_be_with_reload(:project1) { create(:project, namespace: group) } + let_it_be(:package1) { create(:package, project: project1) } + let_it_be_with_reload(:subgroup) { create(:group, parent: group) } + let_it_be_with_reload(:project2) { create(:project, namespace: subgroup) } + let_it_be(:package2) { create(:package, project: project2) } + + let(:finder_class) do + Class.new do + include ::Packages::FinderHelper + + def initialize(user) + @current_user = user + end + + def execute(group) + packages_visible_to_user(@current_user, within_group: group) + end + end + end + + let(:finder) { finder_class.new(user) } + + subject { finder.execute(group) } + + shared_examples 'returning both packages' do + it { is_expected.to contain_exactly(package1, package2) } + end + + shared_examples 'returning package1' do + it { is_expected.to eq [package1]} + end + + shared_examples 'returning no packages' do + it { is_expected.to be_empty } + end + + where(:group_visibility, :subgroup_visibility, :project2_visibility, :user_role, :shared_example_name) do + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :maintainer | 'returning both packages' + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :developer | 'returning both packages' + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :guest | 'returning both packages' + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :anonymous | 'returning both packages' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :maintainer | 'returning both packages' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :developer | 'returning both packages' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :guest | 'returning package1' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :anonymous | 'returning package1' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :maintainer | 'returning both packages' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :developer | 'returning both packages' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :guest | 'returning package1' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :anonymous | 'returning package1' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :maintainer | 'returning both packages' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :developer | 'returning both packages' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :guest | 'returning no packages' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :anonymous | 'returning no packages' + end + + with_them do + before do + unless user_role == :anonymous + group.send("add_#{user_role}", user) + subgroup.send("add_#{user_role}", user) + project1.send("add_#{user_role}", user) + project2.send("add_#{user_role}", user) + end + + project2.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project2_visibility, false)) + subgroup.update!(visibility_level: Gitlab::VisibilityLevel.const_get(subgroup_visibility, false)) + project1.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) + group.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) + end + + it_behaves_like params[:shared_example_name] + end + end + + describe '#projects_visible_to_user' do + using RSpec::Parameterized::TableSyntax + + let_it_be(:user) { create(:user) } + let_it_be_with_reload(:group) { create(:group) } + let_it_be_with_reload(:project1) { create(:project, namespace: group) } + let_it_be_with_reload(:subgroup) { create(:group, parent: group) } + let_it_be_with_reload(:project2) { create(:project, namespace: subgroup) } + + let(:finder_class) do + Class.new do + include ::Packages::FinderHelper + + def initialize(user) + @current_user = user + end + + def execute(group) + projects_visible_to_user(@current_user, within_group: group) + end + end + end + + let(:finder) { finder_class.new(user) } + + subject { finder.execute(group) } + + shared_examples 'returning both projects' do + it { is_expected.to contain_exactly(project1, project2) } + end + + shared_examples 'returning project1' do + it { is_expected.to eq [project1]} + end + + shared_examples 'returning no project' do + it { is_expected.to be_empty } + end + + where(:group_visibility, :subgroup_visibility, :project2_visibility, :user_role, :shared_example_name) do + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :maintainer | 'returning both projects' + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :developer | 'returning both projects' + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :guest | 'returning both projects' + 'PUBLIC' | 'PUBLIC' | 'PUBLIC' | :anonymous | 'returning both projects' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :maintainer | 'returning both projects' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :developer | 'returning both projects' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :guest | 'returning project1' + 'PUBLIC' | 'PUBLIC' | 'PRIVATE' | :anonymous | 'returning project1' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :maintainer | 'returning both projects' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :developer | 'returning both projects' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :guest | 'returning project1' + 'PUBLIC' | 'PRIVATE' | 'PRIVATE' | :anonymous | 'returning project1' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :maintainer | 'returning both projects' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :developer | 'returning both projects' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :guest | 'returning no project' + 'PRIVATE' | 'PRIVATE' | 'PRIVATE' | :anonymous | 'returning no project' + end + + with_them do + before do + unless user_role == :anonymous + group.send("add_#{user_role}", user) + subgroup.send("add_#{user_role}", user) + project1.send("add_#{user_role}", user) + project2.send("add_#{user_role}", user) + end + + project2.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project2_visibility, false)) + subgroup.update!(visibility_level: Gitlab::VisibilityLevel.const_get(subgroup_visibility, false)) + project1.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) + group.update!(visibility_level: Gitlab::VisibilityLevel.const_get(group_visibility, false)) + end + + it_behaves_like params[:shared_example_name] + end + end +end diff --git a/spec/finders/group_projects_finder_spec.rb b/spec/finders/group_projects_finder_spec.rb index c66fdb19260..3fc4393df5d 100644 --- a/spec/finders/group_projects_finder_spec.rb +++ b/spec/finders/group_projects_finder_spec.rb @@ -142,20 +142,40 @@ RSpec.describe GroupProjectsFinder do describe 'with an admin current user' do let(:current_user) { create(:admin) } - context "only shared" do - let(:options) { { only_shared: true } } + context 'when admin mode is enabled', :enable_admin_mode do + context "only shared" do + let(:options) { { only_shared: true } } - it { is_expected.to eq([shared_project_3, shared_project_2, shared_project_1]) } - end + it { is_expected.to contain_exactly(shared_project_3, shared_project_2, shared_project_1) } + end - context "only owned" do - let(:options) { { only_owned: true } } + context "only owned" do + let(:options) { { only_owned: true } } + + it { is_expected.to contain_exactly(private_project, public_project) } + end - it { is_expected.to eq([private_project, public_project]) } + context "all" do + it { is_expected.to contain_exactly(shared_project_3, shared_project_2, shared_project_1, private_project, public_project) } + end end - context "all" do - it { is_expected.to eq([shared_project_3, shared_project_2, shared_project_1, private_project, public_project]) } + context 'when admin mode is disabled' do + context "only shared" do + let(:options) { { only_shared: true } } + + it { is_expected.to contain_exactly(shared_project_3, shared_project_1) } + end + + context "only owned" do + let(:options) { { only_owned: true } } + + it { is_expected.to contain_exactly(public_project) } + end + + context "all" do + it { is_expected.to contain_exactly(shared_project_3, shared_project_1, public_project) } + end end end diff --git a/spec/finders/groups_finder_spec.rb b/spec/finders/groups_finder_spec.rb index c9e9328794e..d69720ae98e 100644 --- a/spec/finders/groups_finder_spec.rb +++ b/spec/finders/groups_finder_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe GroupsFinder do + include AdminModeHelper + describe '#execute' do let(:user) { create(:user) } @@ -23,11 +25,16 @@ RSpec.describe GroupsFinder do :external | { all_available: false } | %i(user_public_group user_internal_group user_private_group) :external | {} | %i(public_group user_public_group user_internal_group user_private_group) - :admin | { all_available: true } | %i(public_group internal_group private_group user_public_group - user_internal_group user_private_group) - :admin | { all_available: false } | %i(user_public_group user_internal_group user_private_group) - :admin | {} | %i(public_group internal_group private_group user_public_group user_internal_group - user_private_group) + :admin_without_admin_mode | { all_available: true } | %i(public_group internal_group user_public_group + user_internal_group user_private_group) + :admin_without_admin_mode | { all_available: false } | %i(user_public_group user_internal_group user_private_group) + :admin_without_admin_mode | {} | %i(public_group internal_group user_public_group user_internal_group user_private_group) + + :admin_with_admin_mode | { all_available: true } | %i(public_group internal_group private_group user_public_group + user_internal_group user_private_group) + :admin_with_admin_mode | { all_available: false } | %i(user_public_group user_internal_group user_private_group) + :admin_with_admin_mode | {} | %i(public_group internal_group private_group user_public_group user_internal_group + user_private_group) end with_them do @@ -52,8 +59,12 @@ RSpec.describe GroupsFinder do create(:user) when :external create(:user, external: true) - when :admin + when :admin_without_admin_mode create(:user, :admin) + when :admin_with_admin_mode + admin = create(:user, :admin) + enable_admin_mode!(admin) + admin end @groups.values_at(:user_private_group, :user_internal_group, :user_public_group).each do |group| group.add_developer(user) diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 0def3412aa7..33b8a5954ae 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -13,7 +13,27 @@ RSpec.describe IssuesFinder do let(:scope) { 'all' } it 'returns all issues' do - expect(issues).to contain_exactly(issue1, issue2, issue3, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue3, issue4, issue5) + end + + context 'user does not have read permissions' do + let(:search_user) { user2 } + + context 'when filtering by project id' do + let(:params) { { project_id: project1.id } } + + it 'returns no issues' do + expect(issues).to be_empty + end + end + + context 'when filtering by group id' do + let(:params) { { group_id: group.id } } + + it 'returns no issues' do + expect(issues).to be_empty + end + end end context 'assignee filtering' do @@ -21,7 +41,7 @@ RSpec.describe IssuesFinder do it_behaves_like 'assignee ID filter' do let(:params) { { assignee_id: user.id } } - let(:expected_issuables) { [issue1, issue2] } + let(:expected_issuables) { [issue1, issue2, issue5] } end it_behaves_like 'assignee NOT ID filter' do @@ -59,7 +79,25 @@ RSpec.describe IssuesFinder do end it_behaves_like 'any assignee filter' do - let(:expected_issuables) { [issue1, issue2, issue3] } + let(:expected_issuables) { [issue1, issue2, issue3, issue5] } + end + end + + context 'filtering by release' do + context 'when the release tag is none' do + let(:params) { { release_tag: 'none' } } + + it 'returns issues without releases' do + expect(issues).to contain_exactly(issue2, issue3, issue4, issue5) + end + end + + context 'when the release tag exists' do + let(:params) { { project_id: project1.id, release_tag: release.tag } } + + it 'returns the issues associated with that release' do + expect(issues).to contain_exactly(issue1) + end end end @@ -68,7 +106,7 @@ RSpec.describe IssuesFinder do let(:params) { { projects: [project1.id] } } it 'returns the issue belonging to the projects' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue5) end end @@ -76,7 +114,7 @@ RSpec.describe IssuesFinder do let(:params) { { projects: Project.id_in(project1.id) } } it 'returns the issue belonging to the projects' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue5) end end end @@ -86,7 +124,7 @@ RSpec.describe IssuesFinder do context 'when include_subgroup param not set' do it 'returns all group issues' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue5) end context 'when projects outside the group are passed' do @@ -101,7 +139,7 @@ RSpec.describe IssuesFinder do let(:params) { { group_id: group.id, projects: [project1.id] } } it 'returns the issue within the group and projects' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue5) end end @@ -109,7 +147,15 @@ RSpec.describe IssuesFinder do let(:params) { { group_id: group.id, projects: Project.id_in(project1.id) } } it 'returns the issue within the group and projects' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue5) + end + end + + context 'when release_tag is passed as a parameter' do + let(:params) { { group_id: group.id, release_tag: 'dne-release-tag' } } + + it 'ignores the release_tag parameter' do + expect(issues).to contain_exactly(issue1, issue5) end end end @@ -120,7 +166,7 @@ RSpec.describe IssuesFinder do end it 'returns all group and subgroup issues' do - expect(issues).to contain_exactly(issue1, issue4) + expect(issues).to contain_exactly(issue1, issue4, issue5) end context 'when mixed projects are passed' do @@ -145,7 +191,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { author_id: user2.id } } } it 'returns issues not created by that user' do - expect(issues).to contain_exactly(issue1, issue2, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue4, issue5) end end @@ -175,7 +221,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { milestone_title: milestone.title } } } it 'returns issues not assigned to that milestone' do - expect(issues).to contain_exactly(issue2, issue3, issue4) + expect(issues).to contain_exactly(issue2, issue3, issue4, issue5) end end @@ -199,7 +245,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { milestone_title: group_milestone.title } } } it 'returns issues not assigned to that group milestone' do - expect(issues).to contain_exactly(issue1, issue4) + expect(issues).to contain_exactly(issue1, issue4, issue5) end end end @@ -208,13 +254,13 @@ RSpec.describe IssuesFinder do let(:params) { { milestone_title: 'None' } } it 'returns issues with no milestone' do - expect(issues).to contain_exactly(issue2, issue3, issue4) + expect(issues).to contain_exactly(issue2, issue3, issue4, issue5) end it 'returns issues with no milestone (deprecated)' do params[:milestone_title] = Milestone::None.title - expect(issues).to contain_exactly(issue2, issue3, issue4) + expect(issues).to contain_exactly(issue2, issue3, issue4, issue5) end end @@ -343,7 +389,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { label_name: label.title } } } it 'returns issues that do not have that label' do - expect(issues).to contain_exactly(issue1, issue3, issue4) + expect(issues).to contain_exactly(issue1, issue3, issue4, issue5) end # IssuableFinder first filters using the outer params (the ones not inside the `not` key.) @@ -383,7 +429,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { label_name: [label.title, label2.title].join(',') } } } it 'returns issues that do not have any of the labels provided' do - expect(issues).to contain_exactly(issue1, issue4) + expect(issues).to contain_exactly(issue1, issue4, issue5) end end end @@ -405,7 +451,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { label_name: [label.title, label2.title].join(',') } } } it 'returns issues that do not have ANY ONE of the labels provided' do - expect(issues).to contain_exactly(issue1, issue4) + expect(issues).to contain_exactly(issue1, issue4, issue5) end end end @@ -414,7 +460,7 @@ RSpec.describe IssuesFinder do let(:params) { { label_name: described_class::Params::FILTER_NONE } } it 'returns issues with no labels' do - expect(issues).to contain_exactly(issue1, issue4) + expect(issues).to contain_exactly(issue1, issue4, issue5) end end @@ -483,14 +529,14 @@ RSpec.describe IssuesFinder do end context 'filtering by issues iids' do - let(:params) { { iids: issue3.iid } } + let(:params) { { iids: [issue3.iid] } } - it 'returns issues with iids match' do - expect(issues).to contain_exactly(issue3) + it 'returns issues where iids match' do + expect(issues).to contain_exactly(issue3, issue5) end context 'using NOT' do - let(:params) { { not: { iids: issue3.iid } } } + let(:params) { { not: { iids: [issue3.iid] } } } it 'returns issues with no iids match' do expect(issues).to contain_exactly(issue1, issue2, issue4) @@ -503,7 +549,7 @@ RSpec.describe IssuesFinder do let(:params) { { state: 'opened' } } it 'returns only opened issues' do - expect(issues).to contain_exactly(issue1, issue2, issue3, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue3, issue4, issue5) end end @@ -519,7 +565,7 @@ RSpec.describe IssuesFinder do let(:params) { { state: 'all' } } it 'returns all issues' do - expect(issues).to contain_exactly(issue1, issue2, issue3, closed_issue, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue3, closed_issue, issue4, issue5) end end @@ -527,7 +573,7 @@ RSpec.describe IssuesFinder do let(:params) { { state: 'invalid_state' } } it 'returns all issues' do - expect(issues).to contain_exactly(issue1, issue2, issue3, closed_issue, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue3, closed_issue, issue4, issue5) end end end @@ -619,7 +665,7 @@ RSpec.describe IssuesFinder do let(:params) { { my_reaction_emoji: 'None' } } it 'returns issues that the user did not react to' do - expect(issues).to contain_exactly(issue2, issue4) + expect(issues).to contain_exactly(issue2, issue4, issue5) end end @@ -642,7 +688,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { my_reaction_emoji: 'thumbsup' } } } it 'returns issues that the user did not thumbsup to' do - expect(issues).to contain_exactly(issue2, issue3, issue4) + expect(issues).to contain_exactly(issue2, issue3, issue4, issue5) end end end @@ -676,7 +722,7 @@ RSpec.describe IssuesFinder do let(:params) { { not: { my_reaction_emoji: 'thumbsdown' } } } it 'returns issues that the user thumbsdown to' do - expect(issues).to contain_exactly(issue1, issue2, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue4, issue5) end end end @@ -687,7 +733,7 @@ RSpec.describe IssuesFinder do context 'no filtering' do it 'returns all issues' do - expect(issues).to contain_exactly(issue1, issue2, issue3, issue4, confidential_issue) + expect(issues).to contain_exactly(issue1, issue2, issue3, issue4, issue5, confidential_issue) end end @@ -703,7 +749,7 @@ RSpec.describe IssuesFinder do let(:params) { { confidential: false } } it 'returns only confdential issues' do - expect(issues).to contain_exactly(issue1, issue2, issue3, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue3, issue4, issue5) end end end @@ -715,7 +761,7 @@ RSpec.describe IssuesFinder do let(:params) { { issue_types: [] } } it 'returns all issues' do - expect(issues).to contain_exactly(incident_issue, issue1, issue2, issue3, issue4) + expect(issues).to contain_exactly(incident_issue, issue1, issue2, issue3, issue4, issue5) end end @@ -731,7 +777,7 @@ RSpec.describe IssuesFinder do let(:params) { { issue_types: ['issue'] } } it 'returns all issues with type issue' do - expect(issues).to contain_exactly(issue1, issue2, issue3, issue4) + expect(issues).to contain_exactly(issue1, issue2, issue3, issue4, issue5) end end @@ -739,7 +785,7 @@ RSpec.describe IssuesFinder do let(:params) { { issue_types: %w(issue incident) } } it 'returns all issues' do - expect(issues).to contain_exactly(incident_issue, issue1, issue2, issue3, issue4) + expect(issues).to contain_exactly(incident_issue, issue1, issue2, issue3, issue4, issue5) end end @@ -790,14 +836,14 @@ RSpec.describe IssuesFinder do let(:scope) { 'assigned_to_me' } it 'returns issue assigned to the user' do - expect(issues).to contain_exactly(issue1, issue2) + expect(issues).to contain_exactly(issue1, issue2, issue5) end context 'filtering by project' do let(:params) { { project_id: project1.id } } it 'returns issues assigned to the user in that project' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue5) end end end @@ -839,7 +885,7 @@ RSpec.describe IssuesFinder do let(:params) { base_params.merge(due_date: Issue::NoDueDate.name) } it 'returns issues with no due date' do - expect(issues).to contain_exactly(issue1) + expect(issues).to contain_exactly(issue1, issue5) end end @@ -872,16 +918,26 @@ RSpec.describe IssuesFinder do describe '#row_count', :request_store do let_it_be(:admin) { create(:admin) } - it 'returns the number of rows for the default state' do - finder = described_class.new(admin) + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns the number of rows for the default state' do + finder = described_class.new(admin) + + expect(finder.row_count).to eq(5) + end + + it 'returns the number of rows for a given state' do + finder = described_class.new(admin, state: 'closed') - expect(finder.row_count).to eq(4) + expect(finder.row_count).to be_zero + end end - it 'returns the number of rows for a given state' do - finder = described_class.new(admin, state: 'closed') + context 'when admin mode is disabled' do + it 'returns no rows' do + finder = described_class.new(admin) - expect(finder.row_count).to be_zero + expect(finder.row_count).to be_zero + end end it 'returns -1 if the query times out' do @@ -950,8 +1006,17 @@ RSpec.describe IssuesFinder do subject { described_class.new(admin_user, params).with_confidentiality_access_check } - it 'returns all issues' do - expect(subject).to include(public_issue, confidential_issue) + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns all issues' do + expect(subject).to include(public_issue, confidential_issue) + end + end + + context 'when admin mode is disabled' do + it 'returns only public issues' do + expect(subject).to include(public_issue) + expect(subject).not_to include(confidential_issue) + end end end end @@ -1023,14 +1088,27 @@ RSpec.describe IssuesFinder do subject { described_class.new(admin_user, params).with_confidentiality_access_check } - it 'returns all issues' do - expect(subject).to include(public_issue, confidential_issue) + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns all issues' do + expect(subject).to include(public_issue, confidential_issue) + end + + it 'does not filter by confidentiality' do + expect(Issue).not_to receive(:where).with(a_string_matching('confidential'), anything) + + subject + end end - it 'does not filter by confidentiality' do - expect(Issue).not_to receive(:where).with(a_string_matching('confidential'), anything) + context 'when admin mode is disabled' do + it 'returns only public issues' do + expect(subject).to include(public_issue) + expect(subject).not_to include(confidential_issue) + end - subject + it 'filters by confidentiality' do + expect(subject.to_sql).to match("issues.confidential") + end end end end diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 7b59b581b1c..6fdfe780463 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -76,13 +76,40 @@ RSpec.describe MergeRequestsFinder do expect(merge_requests).to contain_exactly(merge_request3, merge_request4) end - it 'filters by commit sha' do - merge_requests = described_class.new( - user, - commit_sha: merge_request5.merge_request_diff.last_commit_sha - ).execute + context 'filters by commit sha' do + subject(:merge_requests) { described_class.new(user, commit_sha: commit_sha).execute } + + context 'when commit belongs to the merge request' do + let(:commit_sha) { merge_request5.merge_request_diff.last_commit_sha } + + it 'filters by commit sha' do + is_expected.to contain_exactly(merge_request5) + end + end + + context 'when commit is a squash commit' do + before do + merge_request4.update!(squash_commit_sha: commit_sha) + end + + let(:commit_sha) { '1234abcd' } + + it 'filters by commit sha' do + is_expected.to contain_exactly(merge_request4) + end + end + + context 'when commit is a merge commit' do + before do + merge_request4.update!(merge_commit_sha: commit_sha) + end + + let(:commit_sha) { '1234dcba' } - expect(merge_requests).to contain_exactly(merge_request5) + it 'filters by commit sha' do + is_expected.to contain_exactly(merge_request4) + end + end end context 'filters by merged_at date' do @@ -697,10 +724,18 @@ RSpec.describe MergeRequestsFinder do context 'with admin user' do let(:user) { create(:user, :admin) } - it 'returns all merge requests' do - expect(merge_requests).to eq( - [mr_internal_private_repo_access, mr_private_repo_access, mr_internal, mr_private, mr_public] - ) + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns all merge requests' do + expect(merge_requests).to contain_exactly( + mr_internal_private_repo_access, mr_private_repo_access, mr_internal, mr_private, mr_public + ) + end + end + + context 'when admin mode is disabled' do + it 'returns public and internal merge requests' do + expect(merge_requests).to contain_exactly(mr_internal, mr_public) + end end end diff --git a/spec/finders/packages/debian/distributions_finder_spec.rb b/spec/finders/packages/debian/distributions_finder_spec.rb new file mode 100644 index 00000000000..f141b13e394 --- /dev/null +++ b/spec/finders/packages/debian/distributions_finder_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::DistributionsFinder do + it_behaves_like 'Debian Distributions Finder', :debian_project_distribution, true + it_behaves_like 'Debian Distributions Finder', :debian_group_distribution, false + + context 'with nil container' do + let(:service) { described_class.new(nil) } + + subject { service.execute.to_a } + + it 'raises error' do + expect { subject }.to raise_error ArgumentError, "Unexpected container type of 'NilClass'" + end + end + + context 'with unexpected container type' do + let(:service) { described_class.new(:invalid) } + + subject { service.execute.to_a } + + it 'raises error' do + expect { subject }.to raise_error ArgumentError, "Unexpected container type of 'Symbol'" + end + end +end diff --git a/spec/finders/packages/group_packages_finder_spec.rb b/spec/finders/packages/group_packages_finder_spec.rb index 0db69de65a5..8dd53b9c3f9 100644 --- a/spec/finders/packages/group_packages_finder_spec.rb +++ b/spec/finders/packages/group_packages_finder_spec.rb @@ -127,12 +127,6 @@ RSpec.describe Packages::GroupPackagesFinder do it { is_expected.to match_array([package1, package2]) } end - context 'does not include packages without version number' do - let_it_be(:package_without_version) { create(:maven_package, project: project, version: nil) } - - it { is_expected.not_to include(package_without_version) } - end - context 'with package_name' do let_it_be(:named_package) { create(:maven_package, project: project, name: 'maven') } let(:params) { { package_name: package_name } } @@ -151,6 +145,8 @@ RSpec.describe Packages::GroupPackagesFinder do end end end + + it_behaves_like 'concerning versionless param' end context 'group has package of all types' do diff --git a/spec/finders/packages/maven/package_finder_spec.rb b/spec/finders/packages/maven/package_finder_spec.rb index 239e8c10f52..b955c331f28 100644 --- a/spec/finders/packages/maven/package_finder_spec.rb +++ b/spec/finders/packages/maven/package_finder_spec.rb @@ -1,57 +1,81 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe ::Packages::Maven::PackageFinder do - let(:user) { create(:user) } - let(:group) { create(:group) } - let(:project) { create(:project, namespace: group) } - let(:package) { create(:maven_package, project: project) } + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, namespace: group) } + let_it_be(:package) { create(:maven_package, project: project) } + + let(:param_path) { nil } + let(:param_project) { nil } + let(:param_group) { nil } + let(:finder) { described_class.new(param_path, user, project: param_project, group: param_group) } before do group.add_developer(user) end describe '#execute!' do - context 'within the project' do - it 'returns a package' do - finder = described_class.new(package.maven_metadatum.path, user, project: project) - - expect(finder.execute!).to eq(package) - end + subject { finder.execute! } - it 'raises an error' do - finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user, project: project) + shared_examples 'handling valid and invalid paths' do + context 'with a valid path' do + let(:param_path) { package.maven_metadatum.path } - expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) + it { is_expected.to eq(package) } end - end - context 'across all projects' do - it 'returns a package' do - finder = described_class.new(package.maven_metadatum.path, user) + context 'with an invalid path' do + let(:param_path) { 'com/example/my-app/1.0-SNAPSHOT' } - expect(finder.execute!).to eq(package) + it 'raises an error' do + expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + end end + end - it 'raises an error' do - finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user) + context 'within the project' do + let(:param_project) { project } - expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) - end + it_behaves_like 'handling valid and invalid paths' end context 'within a group' do - it 'returns a package' do - finder = described_class.new(package.maven_metadatum.path, user, group: group) + let(:param_group) { group } - expect(finder.execute!).to eq(package) - end + it_behaves_like 'handling valid and invalid paths' + end + context 'across all projects' do it 'raises an error' do - finder = described_class.new('com/example/my-app/1.0-SNAPSHOT', user, group: group) + expect { subject }.to raise_error(ActiveRecord::RecordNotFound) + end + end + + context 'versionless maven-metadata.xml package' do + let_it_be(:sub_group1) { create(:group, parent: group) } + let_it_be(:sub_group2) { create(:group, parent: group) } + let_it_be(:project1) { create(:project, group: sub_group1) } + let_it_be(:project2) { create(:project, group: sub_group2) } + let_it_be(:project3) { create(:project, group: sub_group1) } + let_it_be(:package_name) { 'foo' } + let_it_be(:package1) { create(:maven_package, project: project1, name: package_name, version: nil) } + let_it_be(:package2) { create(:maven_package, project: project2, name: package_name, version: nil) } + let_it_be(:package3) { create(:maven_package, project: project3, name: package_name, version: nil) } - expect { finder.execute! }.to raise_error(ActiveRecord::RecordNotFound) + let(:param_group) { group } + let(:param_path) { package_name } + + before do + sub_group1.add_developer(user) + sub_group2.add_developer(user) + # the package with the most recently published file should be returned + create(:package_file, :xml, package: package2) end + + it { is_expected.to eq(package2) } end end end diff --git a/spec/finders/packages/nuget/package_finder_spec.rb b/spec/finders/packages/nuget/package_finder_spec.rb index 9295d0c7a2f..10b5f6c8ec2 100644 --- a/spec/finders/packages/nuget/package_finder_spec.rb +++ b/spec/finders/packages/nuget/package_finder_spec.rb @@ -2,74 +2,117 @@ require 'spec_helper' RSpec.describe Packages::Nuget::PackageFinder do - let_it_be(:package1) { create(:nuget_package) } - let_it_be(:project) { package1.project } + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:subgroup) { create(:group, parent: group) } + let_it_be(:project) { create(:project, namespace: subgroup) } + let_it_be(:package1) { create(:nuget_package, project: project) } let_it_be(:package2) { create(:nuget_package, name: package1.name, version: '2.0.0', project: project) } let_it_be(:package3) { create(:nuget_package, name: 'Another.Dummy.Package', project: project) } + let_it_be(:other_package_1) { create(:nuget_package, name: package1.name, version: package1.version) } + let_it_be(:other_package_2) { create(:nuget_package, name: package1.name, version: package2.version) } let(:package_name) { package1.name } let(:package_version) { nil } let(:limit) { 50 } describe '#execute!' do - subject { described_class.new(project, package_name: package_name, package_version: package_version, limit: limit).execute } + subject { described_class.new(user, target, package_name: package_name, package_version: package_version, limit: limit).execute } - it { is_expected.to match_array([package1, package2]) } + shared_examples 'handling all the conditions' do + it { is_expected.to match_array([package1, package2]) } - context 'with lower case package name' do - let(:package_name) { package1.name.downcase } + context 'with lower case package name' do + let(:package_name) { package1.name.downcase } - it { is_expected.to match_array([package1, package2]) } - end + it { is_expected.to match_array([package1, package2]) } + end - context 'with unknown package name' do - let(:package_name) { 'foobar' } + context 'with unknown package name' do + let(:package_name) { 'foobar' } - it { is_expected.to be_empty } - end + it { is_expected.to be_empty } + end - context 'with valid version' do - let(:package_version) { '2.0.0' } + context 'with valid version' do + let(:package_version) { '2.0.0' } - it { is_expected.to match_array([package2]) } - end + it { is_expected.to match_array([package2]) } + end - context 'with unknown version' do - let(:package_version) { 'foobar' } + context 'with unknown version' do + let(:package_version) { 'foobar' } - it { is_expected.to be_empty } - end + it { is_expected.to be_empty } + end + + context 'with limit hit' do + let_it_be(:package4) { create(:nuget_package, name: package1.name, project: project) } + let_it_be(:package5) { create(:nuget_package, name: package1.name, project: project) } + let_it_be(:package6) { create(:nuget_package, name: package1.name, project: project) } + let(:limit) { 2 } + + it { is_expected.to match_array([package5, package6]) } + end + + context 'with downcase package name' do + let(:package_name) { package1.name.downcase } + + it { is_expected.to match_array([package1, package2]) } + end - context 'with limit hit' do - let_it_be(:package4) { create(:nuget_package, name: package1.name, project: project) } - let_it_be(:package5) { create(:nuget_package, name: package1.name, project: project) } - let_it_be(:package6) { create(:nuget_package, name: package1.name, project: project) } - let(:limit) { 2 } + context 'with prefix wildcard' do + let(:package_name) { "%#{package1.name[3..-1]}" } - it { is_expected.to match_array([package5, package6]) } + it { is_expected.to match_array([package1, package2]) } + end + + context 'with suffix wildcard' do + let(:package_name) { "#{package1.name[0..-3]}%" } + + it { is_expected.to match_array([package1, package2]) } + end + + context 'with surrounding wildcards' do + let(:package_name) { "%#{package1.name[3..-3]}%" } + + it { is_expected.to match_array([package1, package2]) } + end end - context 'with downcase package name' do - let(:package_name) { package1.name.downcase } + context 'with a project' do + let(:target) { project } - it { is_expected.to match_array([package1, package2]) } + before do + project.add_developer(user) + end + + it_behaves_like 'handling all the conditions' end - context 'with prefix wildcard' do - let(:package_name) { "%#{package1.name[3..-1]}" } + context 'with a subgroup' do + let(:target) { subgroup } - it { is_expected.to match_array([package1, package2]) } + before do + subgroup.add_developer(user) + end + + it_behaves_like 'handling all the conditions' end - context 'with suffix wildcard' do - let(:package_name) { "#{package1.name[0..-3]}%" } + context 'with a group' do + let(:target) { group } - it { is_expected.to match_array([package1, package2]) } + before do + group.add_developer(user) + end + + it_behaves_like 'handling all the conditions' end - context 'with surrounding wildcards' do - let(:package_name) { "%#{package1.name[3..-3]}%" } + context 'with nil' do + let(:target) { nil } - it { is_expected.to match_array([package1, package2]) } + it { is_expected.to be_empty } end end end diff --git a/spec/finders/packages/packages_finder_spec.rb b/spec/finders/packages/packages_finder_spec.rb index 925b003bb8e..77a171db144 100644 --- a/spec/finders/packages/packages_finder_spec.rb +++ b/spec/finders/packages/packages_finder_spec.rb @@ -81,10 +81,6 @@ RSpec.describe ::Packages::PackagesFinder do it { is_expected.to match_array([conan_package, maven_package]) } end - context 'does not include packages without version number' do - let_it_be(:package_without_version) { create(:maven_package, project: project, version: nil) } - - it { is_expected.not_to include(package_without_version) } - end + it_behaves_like 'concerning versionless param' end end diff --git a/spec/finders/projects_finder_spec.rb b/spec/finders/projects_finder_spec.rb index 57977fb69b4..4d9ff30daba 100644 --- a/spec/finders/projects_finder_spec.rb +++ b/spec/finders/projects_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ProjectsFinder, :do_not_mock_admin_mode do +RSpec.describe ProjectsFinder do include AdminModeHelper describe '#execute' do @@ -353,7 +353,7 @@ RSpec.describe ProjectsFinder, :do_not_mock_admin_mode do end before do - stub_feature_flags(project_finder_similarity_sort: true) + stub_feature_flags(project_finder_similarity_sort: current_user) end it { is_expected.to eq([internal_project2, internal_project4, internal_project3]) } diff --git a/spec/finders/snippets_finder_spec.rb b/spec/finders/snippets_finder_spec.rb index 6fc1cbcee0a..9c9a04a4df5 100644 --- a/spec/finders/snippets_finder_spec.rb +++ b/spec/finders/snippets_finder_spec.rb @@ -106,12 +106,18 @@ RSpec.describe SnippetsFinder do expect(snippets).to contain_exactly(public_personal_snippet) end - it 'returns all snippets for an admin' do + it 'returns all snippets for an admin in admin mode', :enable_admin_mode do snippets = described_class.new(admin, author: user).execute expect(snippets).to contain_exactly(private_personal_snippet, internal_personal_snippet, public_personal_snippet) end + it 'returns all public and internal snippets for an admin without admin mode' do + snippets = described_class.new(admin, author: user).execute + + expect(snippets).to contain_exactly(internal_personal_snippet, public_personal_snippet) + end + context 'when author is not valid' do it 'returns quickly' do finder = described_class.new(admin, author: non_existing_record_id) @@ -180,12 +186,18 @@ RSpec.describe SnippetsFinder do expect(snippets).to contain_exactly(private_project_snippet) end - it 'returns all snippets for an admin' do + it 'returns all snippets for an admin in admin mode', :enable_admin_mode do snippets = described_class.new(admin, project: project).execute expect(snippets).to contain_exactly(private_project_snippet, internal_project_snippet, public_project_snippet) end + it 'returns public and internal snippets for an admin without admin mode' do + snippets = described_class.new(admin, project: project).execute + + expect(snippets).to contain_exactly(internal_project_snippet, public_project_snippet) + end + context 'filter by author' do let!(:other_user) { create(:user) } let!(:other_private_project_snippet) { create(:project_snippet, :private, project: project, author: other_user) } @@ -218,7 +230,7 @@ RSpec.describe SnippetsFinder do end context 'filter by snippet type' do - context 'when filtering by only_personal snippet' do + context 'when filtering by only_personal snippet', :enable_admin_mode do it 'returns only personal snippet' do snippets = described_class.new(admin, only_personal: true).execute @@ -228,7 +240,7 @@ RSpec.describe SnippetsFinder do end end - context 'when filtering by only_project snippet' do + context 'when filtering by only_project snippet', :enable_admin_mode do it 'returns only project snippet' do snippets = described_class.new(admin, only_project: true).execute @@ -239,7 +251,7 @@ RSpec.describe SnippetsFinder do end end - context 'filtering by ids' do + context 'filtering by ids', :enable_admin_mode do it 'returns only personal snippet' do snippets = described_class.new( admin, ids: [private_personal_snippet.id, @@ -265,13 +277,21 @@ RSpec.describe SnippetsFinder do ) end - it 'returns all personal snippets for admins' do + it 'returns all personal snippets for admins when in admin mode', :enable_admin_mode do snippets = described_class.new(admin, explore: true).execute expect(snippets).to contain_exactly( private_personal_snippet, internal_personal_snippet, public_personal_snippet ) end + + it 'also returns internal personal snippets for admins without admin mode' do + snippets = described_class.new(admin, explore: true).execute + + expect(snippets).to contain_exactly( + internal_personal_snippet, public_personal_snippet + ) + end end context 'when the user cannot read cross project' do @@ -302,7 +322,7 @@ RSpec.describe SnippetsFinder do end end - context 'no sort param is provided' do + context 'no sort param is provided', :enable_admin_mode do it 'returns snippets sorted by id' do snippets = described_class.new(admin).execute @@ -310,7 +330,7 @@ RSpec.describe SnippetsFinder do end end - context 'sort param is provided' do + context 'sort param is provided', :enable_admin_mode do it 'returns snippets sorted by sort param' do snippets = described_class.new(admin, sort: 'updated_desc').execute diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb index 0fdd6ab402d..2da864b9a46 100644 --- a/spec/finders/template_finder_spec.rb +++ b/spec/finders/template_finder_spec.rb @@ -14,6 +14,7 @@ RSpec.describe TemplateFinder do :gitlab_ci_ymls | described_class :licenses | ::LicenseTemplateFinder :metrics_dashboard_ymls | described_class + :gitlab_ci_syntax_ymls | described_class end with_them do @@ -30,6 +31,7 @@ RSpec.describe TemplateFinder do :gitignores | 'Actionscript' :gitlab_ci_ymls | 'Android' :metrics_dashboard_ymls | 'Default' + :gitlab_ci_syntax_ymls | 'Artifacts example' end with_them do diff --git a/spec/finders/users_finder_spec.rb b/spec/finders/users_finder_spec.rb index a04f5452fcd..d9cc71106d5 100644 --- a/spec/finders/users_finder_spec.rb +++ b/spec/finders/users_finder_spec.rb @@ -12,7 +12,7 @@ RSpec.describe UsersFinder do it 'returns all users' do users = described_class.new(user).execute - expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user, internal_user) + expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user, internal_user, admin_user) end it 'filters by username' do @@ -48,13 +48,13 @@ RSpec.describe UsersFinder do it 'filters by active users' do users = described_class.new(user, active: true).execute - expect(users).to contain_exactly(user, normal_user, omniauth_user) + expect(users).to contain_exactly(user, normal_user, omniauth_user, admin_user) end it 'returns no external users' do users = described_class.new(user, external: true).execute - expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user, internal_user) + expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user, internal_user, admin_user) end it 'filters by created_at' do @@ -71,7 +71,7 @@ RSpec.describe UsersFinder do it 'filters by non internal users' do users = described_class.new(user, non_internal: true).execute - expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user) + expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user, admin_user) end it 'does not filter by custom attributes' do @@ -80,17 +80,22 @@ RSpec.describe UsersFinder do custom_attributes: { foo: 'bar' } ).execute - expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user, internal_user) + expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user, internal_user, admin_user) end it 'orders returned results' do users = described_class.new(user, sort: 'id_asc').execute - expect(users).to eq([normal_user, blocked_user, omniauth_user, internal_user, user]) + expect(users).to eq([normal_user, admin_user, blocked_user, omniauth_user, internal_user, user]) + end + + it 'does not filter by admins' do + users = described_class.new(user, admins: true).execute + expect(users).to contain_exactly(user, normal_user, admin_user, blocked_user, omniauth_user, internal_user) end end - context 'with an admin user' do + context 'with an admin user', :enable_admin_mode do let(:admin) { create(:admin) } it 'filters by external users' do @@ -102,7 +107,13 @@ RSpec.describe UsersFinder do it 'returns all users' do users = described_class.new(admin).execute - expect(users).to contain_exactly(admin, normal_user, blocked_user, external_user, omniauth_user, internal_user) + expect(users).to contain_exactly(admin, normal_user, blocked_user, external_user, omniauth_user, internal_user, admin_user) + end + + it 'returns only admins' do + users = described_class.new(admin, admins: true).execute + + expect(users).to contain_exactly(admin, admin_user) end it 'filters by custom attributes' do |