diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/finders | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/finders')
19 files changed, 467 insertions, 131 deletions
diff --git a/spec/finders/autocomplete/users_finder_spec.rb b/spec/finders/autocomplete/users_finder_spec.rb index 28bd7e12916..9b3421d1b4f 100644 --- a/spec/finders/autocomplete/users_finder_spec.rb +++ b/spec/finders/autocomplete/users_finder_spec.rb @@ -3,16 +3,20 @@ require 'spec_helper' RSpec.describe Autocomplete::UsersFinder do + # TODO update when multiple owners are possible in projects + # https://gitlab.com/gitlab-org/gitlab/-/issues/21432 + describe '#execute' do - let!(:user1) { create(:user, username: 'johndoe') } - let!(:user2) { create(:user, :blocked, username: 'notsorandom') } - let!(:external_user) { create(:user, :external) } - let!(:omniauth_user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') } + let_it_be(:user1) { create(:user, name: 'zzzzzname', username: 'johndoe') } + let_it_be(:user2) { create(:user, :blocked, username: 'notsorandom') } + let_it_be(:external_user) { create(:user, :external) } + let_it_be(:omniauth_user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') } + let(:current_user) { create(:user) } let(:params) { {} } - let(:project) { nil } - let(:group) { nil } + let_it_be(:project) { nil } + let_it_be(:group) { nil } subject { described_class.new(params: params, current_user: current_user, project: project, group: group).execute.to_a } @@ -23,33 +27,53 @@ RSpec.describe Autocomplete::UsersFinder do end context 'when project passed' do - let(:project) { create(:project) } + let_it_be(:project) { create(:project) } - it { is_expected.to match_array([project.owner]) } + it { is_expected.to match_array([project.first_owner]) } context 'when author_id passed' do context 'and author is active' do let(:params) { { author_id: user1.id } } - it { is_expected.to match_array([project.owner, user1]) } + it { is_expected.to match_array([project.first_owner, user1]) } end context 'and author is blocked' do let(:params) { { author_id: user2.id } } - it { is_expected.to match_array([project.owner]) } + it { is_expected.to match_array([project.first_owner]) } + end + end + + context 'searching with less than 3 characters' do + let(:params) { { search: 'zz' } } + + before do + project.add_guest(user1) + end + + it 'allows partial matches' do + expect(subject).to contain_exactly(user1) end end end context 'when group passed and project not passed' do - let(:group) { create(:group, :public) } + let_it_be(:group) { create(:group, :public) } - before do + before_all do group.add_users([user1], GroupMember::DEVELOPER) end it { is_expected.to match_array([user1]) } + + context 'searching with less than 3 characters' do + let(:params) { { search: 'zz' } } + + it 'allows partial matches' do + expect(subject).to contain_exactly(user1) + end + end end context 'when passed a subgroup' do @@ -73,6 +97,14 @@ RSpec.describe Autocomplete::UsersFinder do let(:params) { { search: 'johndoe' } } it { is_expected.to match_array([user1]) } + + context 'searching with less than 3 characters' do + let(:params) { { search: 'zz' } } + + it 'does not allow partial matches' do + expect(subject).to be_empty + end + end end context 'when filtered by skip_users' 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 cf15a00323b..5352cfe5238 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 @@ -6,7 +6,7 @@ RSpec.describe Ci::DailyBuildGroupReportResultsFinder do describe '#execute' do let_it_be(:project) { create(:project, :private) } let(:user_without_permission) { create(:user) } - let_it_be(:user_with_permission) { project.owner } + let_it_be(:user_with_permission) { project.first_owner } let_it_be(:ref_path) { 'refs/heads/master' } let(:limit) { nil } let_it_be(:default_branch) { false } diff --git a/spec/finders/ci/jobs_finder_spec.rb b/spec/finders/ci/jobs_finder_spec.rb index ab056dd26e8..959716b1fd3 100644 --- a/spec/finders/ci/jobs_finder_spec.rb +++ b/spec/finders/ci/jobs_finder_spec.rb @@ -126,4 +126,41 @@ RSpec.describe Ci::JobsFinder, '#execute' do end end end + + context 'a runner is present' do + let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) } + let_it_be(:job_4) { create(:ci_build, :success, runner: runner) } + + subject { described_class.new(current_user: user, runner: runner, params: params).execute } + + context 'user has access to the runner', :enable_admin_mode do + let(:user) { admin } + + it 'returns jobs for the specified project' do + expect(subject).to match_array([job_4]) + end + end + + context 'user has no access to project builds' do + let_it_be(:guest) { create(:user) } + + let(:user) { guest } + + before do + project.add_guest(guest) + end + + it 'returns no jobs' do + expect(subject).to be_empty + end + end + + context 'without user' do + let(:user) { nil } + + it 'returns no jobs' do + expect(subject).to be_empty + end + end + end end diff --git a/spec/finders/ci/runners_finder_spec.rb b/spec/finders/ci/runners_finder_spec.rb index dac244e4300..e7ec4f01995 100644 --- a/spec/finders/ci/runners_finder_spec.rb +++ b/spec/finders/ci/runners_finder_spec.rb @@ -91,8 +91,8 @@ RSpec.describe Ci::RunnersFinder do end context 'sorting' do - let_it_be(:runner1) { create :ci_runner, created_at: '2018-07-12 07:00', contacted_at: 1.minute.ago } - let_it_be(:runner2) { create :ci_runner, created_at: '2018-07-12 08:00', contacted_at: 3.minutes.ago } + let_it_be(:runner1) { create :ci_runner, created_at: '2018-07-12 07:00', contacted_at: 1.minute.ago, token_expires_at: '2022-02-15 07:00' } + let_it_be(:runner2) { create :ci_runner, created_at: '2018-07-12 08:00', contacted_at: 3.minutes.ago, token_expires_at: '2022-02-15 06:00' } let_it_be(:runner3) { create :ci_runner, created_at: '2018-07-12 09:00', contacted_at: 2.minutes.ago } subject do @@ -142,6 +142,22 @@ RSpec.describe Ci::RunnersFinder do is_expected.to eq [runner1, runner3, runner2] end end + + context 'with sort param equal to token_expires_at_asc' do + let(:params) { { sort: 'token_expires_at_asc' } } + + it 'sorts by contacted_at ascending' do + is_expected.to eq [runner2, runner1, runner3] + end + end + + context 'with sort param equal to token_expires_at_desc' do + let(:params) { { sort: 'token_expires_at_desc' } } + + it 'sorts by contacted_at descending' do + is_expected.to eq [runner3, runner1, runner2] + end + end end context 'by non admin user' do @@ -206,7 +222,7 @@ RSpec.describe Ci::RunnersFinder do sub_group_4.runners << runner_sub_group_4 end - shared_examples '#execute' do + describe '#execute' do subject { described_class.new(current_user: user, params: params).execute } shared_examples 'membership equal to :descendants' do @@ -349,16 +365,6 @@ RSpec.describe Ci::RunnersFinder do end end - it_behaves_like '#execute' - - context 'when the FF ci_find_runners_by_ci_mirrors is disabled' do - before do - stub_feature_flags(ci_find_runners_by_ci_mirrors: false) - end - - it_behaves_like '#execute' - end - describe '#sort_key' do subject { described_class.new(current_user: user, params: params.merge(group: group)).sort_key } diff --git a/spec/finders/clusters/agents_finder_spec.rb b/spec/finders/clusters/agents_finder_spec.rb index 0996d76b723..4ec798daa99 100644 --- a/spec/finders/clusters/agents_finder_spec.rb +++ b/spec/finders/clusters/agents_finder_spec.rb @@ -15,7 +15,11 @@ RSpec.describe Clusters::AgentsFinder do it { is_expected.to contain_exactly(matching_agent) } context 'user does not have permission' do - let(:user) { create(:user, developer_projects: [project]) } + let(:user) { create(:user) } + + before do + project.add_reporter(user) + end it { is_expected.to be_empty } end diff --git a/spec/finders/crm/contacts_finder_spec.rb b/spec/finders/crm/contacts_finder_spec.rb new file mode 100644 index 00000000000..151af1ad825 --- /dev/null +++ b/spec/finders/crm/contacts_finder_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Crm::ContactsFinder do + let_it_be(:user) { create(:user) } + + describe '#execute' do + subject { described_class.new(user, group: group).execute } + + context 'when customer relations feature is enabled for the group' do + let_it_be(:root_group) { create(:group, :crm_enabled) } + let_it_be(:group) { create(:group, parent: root_group) } + + let_it_be(:contact_1) { create(:contact, group: root_group) } + let_it_be(:contact_2) { create(:contact, group: root_group) } + + context 'when user does not have permissions to see contacts in the group' do + it 'returns an empty array' do + expect(subject).to be_empty + end + end + + context 'when user is member of the root group' do + before do + root_group.add_developer(user) + end + + context 'when feature flag is disabled' do + before do + stub_feature_flags(customer_relations: false) + end + + it 'returns an empty array' do + expect(subject).to be_empty + end + end + + context 'when feature flag is enabled' do + it 'returns all group contacts' do + expect(subject).to match_array([contact_1, contact_2]) + end + end + end + + context 'when user is member of the sub group' do + before do + group.add_developer(user) + end + + it 'returns an empty array' do + expect(subject).to be_empty + end + end + end + + context 'when customer relations feature is disabled for the group' do + let_it_be(:group) { create(:group) } + let_it_be(:contact) { create(:contact, group: group) } + + before do + group.add_developer(user) + end + + it 'returns an empty array' do + expect(subject).to be_empty + end + end + end +end diff --git a/spec/finders/deployments_finder_spec.rb b/spec/finders/deployments_finder_spec.rb index 6d9d0c33de3..51c293bcfd1 100644 --- a/spec/finders/deployments_finder_spec.rb +++ b/spec/finders/deployments_finder_spec.rb @@ -222,11 +222,7 @@ RSpec.describe DeploymentsFinder do end describe 'enforce sorting to `updated_at` sorting' do - let(:params) { { **base_params, updated_before: 1.day.ago, order_by: 'id', sort: 'asc' } } - - before do - allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) - end + let(:params) { { **base_params, updated_before: 1.day.ago, order_by: 'id', sort: 'asc', raise_for_inefficient_updated_at_query: false } } it 'sorts by only one column' do expect(subject.order_values.size).to eq(2) diff --git a/spec/finders/environments/environments_by_deployments_finder_spec.rb b/spec/finders/environments/environments_by_deployments_finder_spec.rb index 8349092c79e..c8e6b038634 100644 --- a/spec/finders/environments/environments_by_deployments_finder_spec.rb +++ b/spec/finders/environments/environments_by_deployments_finder_spec.rb @@ -64,6 +64,22 @@ RSpec.describe Environments::EnvironmentsByDeploymentsFinder do end end + context 'sha deployment' do + before do + create(:deployment, :success, environment: environment, sha: project.commit.id) + end + + it 'returns environment' do + expect(described_class.new(project, user, sha: project.commit.id).execute) + .to contain_exactly(environment) + end + + it 'does not return environment when sha is different' do + expect(described_class.new(project, user, sha: '1234').execute) + .to be_empty + end + end + context 'commit deployment' do before do create(:deployment, :success, environment: environment, ref: 'master', sha: project.commit.id) diff --git a/spec/finders/group_descendants_finder_spec.rb b/spec/finders/group_descendants_finder_spec.rb index 59eeb078e9e..5c5db874e85 100644 --- a/spec/finders/group_descendants_finder_spec.rb +++ b/spec/finders/group_descendants_finder_spec.rb @@ -68,6 +68,12 @@ RSpec.describe GroupDescendantsFinder do expect(finder.execute).to be_empty end + it 'does not include projects aimed for deletion' do + _project_aimed_for_deletion = create(:project, :archived, marked_for_deletion_at: 2.days.ago, pending_delete: false) + + expect(finder.execute).to be_empty + end + context 'with a filter' do let(:params) { { filter: 'test' } } @@ -165,8 +171,8 @@ RSpec.describe GroupDescendantsFinder do end context 'with nested groups' do - let!(:project) { create(:project, namespace: group) } - let!(:subgroup) { create(:group, :private, parent: group) } + let_it_be(:project) { create(:project, namespace: group) } + let_it_be_with_reload(:subgroup) { create(:group, :private, parent: group) } describe '#execute' do it 'contains projects and subgroups' do @@ -208,57 +214,69 @@ RSpec.describe GroupDescendantsFinder do context 'with a filter' do let(:params) { { filter: 'test' } } - it 'contains only matching projects and subgroups' do - matching_project = create(:project, namespace: group, name: 'Testproject') - matching_subgroup = create(:group, name: 'testgroup', parent: group) + shared_examples 'filter examples' do + it 'contains only matching projects and subgroups' do + matching_project = create(:project, namespace: group, name: 'Testproject') + matching_subgroup = create(:group, name: 'testgroup', parent: group) - expect(finder.execute).to contain_exactly(matching_subgroup, matching_project) - end + expect(finder.execute).to contain_exactly(matching_subgroup, matching_project) + end - it 'does not include subgroups the user does not have access to' do - _invisible_subgroup = create(:group, :private, parent: group, name: 'test1') - other_subgroup = create(:group, :private, parent: group, name: 'test2') - public_subgroup = create(:group, :public, parent: group, name: 'test3') - other_subsubgroup = create(:group, :private, parent: other_subgroup, name: 'test4') - other_user = create(:user) - other_subgroup.add_developer(other_user) + it 'does not include subgroups the user does not have access to' do + _invisible_subgroup = create(:group, :private, parent: group, name: 'test1') + other_subgroup = create(:group, :private, parent: group, name: 'test2') + public_subgroup = create(:group, :public, parent: group, name: 'test3') + other_subsubgroup = create(:group, :private, parent: other_subgroup, name: 'test4') + other_user = create(:user) + other_subgroup.add_developer(other_user) - finder = described_class.new(current_user: other_user, - parent_group: group, - params: params) + finder = described_class.new(current_user: other_user, + parent_group: group, + params: params) - expect(finder.execute).to contain_exactly(other_subgroup, public_subgroup, other_subsubgroup) - end + expect(finder.execute).to contain_exactly(other_subgroup, public_subgroup, other_subsubgroup) + end - context 'with matching children' do - it 'includes a group that has a subgroup matching the query and its parent' do - matching_subgroup = create(:group, :private, name: 'testgroup', parent: subgroup) + context 'with matching children' do + it 'includes a group that has a subgroup matching the query and its parent' do + matching_subgroup = create(:group, :private, name: 'testgroup', parent: subgroup) - expect(finder.execute).to contain_exactly(subgroup, matching_subgroup) - end + expect(finder.execute).to contain_exactly(subgroup, matching_subgroup) + end - it 'includes the parent of a matching project' do - matching_project = create(:project, namespace: subgroup, name: 'Testproject') + it 'includes the parent of a matching project' do + matching_project = create(:project, namespace: subgroup, name: 'Testproject') - expect(finder.execute).to contain_exactly(subgroup, matching_project) - end + expect(finder.execute).to contain_exactly(subgroup, matching_project) + end + + context 'with a small page size' do + let(:params) { { filter: 'test', per_page: 1 } } - context 'with a small page size' do - let(:params) { { filter: 'test', per_page: 1 } } + it 'contains all the ancestors of a matching subgroup regardless the page size' do + subgroup = create(:group, :private, parent: group) + matching = create(:group, :private, name: 'testgroup', parent: subgroup) - it 'contains all the ancestors of a matching subgroup regardless the page size' do - subgroup = create(:group, :private, parent: group) - matching = create(:group, :private, name: 'testgroup', parent: subgroup) + expect(finder.execute).to contain_exactly(subgroup, matching) + end + end + + it 'does not include the parent itself' do + group.update!(name: 'test') - expect(finder.execute).to contain_exactly(subgroup, matching) + expect(finder.execute).not_to include(group) end end + end - it 'does not include the parent itself' do - group.update!(name: 'test') + it_behaves_like 'filter examples' - expect(finder.execute).not_to include(group) + context 'when feature flag :linear_group_descendants_finder_upto is disabled' do + before do + stub_feature_flags(linear_group_descendants_finder_upto: false) end + + it_behaves_like 'filter examples' end end end diff --git a/spec/finders/group_projects_finder_spec.rb b/spec/finders/group_projects_finder_spec.rb index 3fc4393df5d..4189be94cc1 100644 --- a/spec/finders/group_projects_finder_spec.rb +++ b/spec/finders/group_projects_finder_spec.rb @@ -9,13 +9,29 @@ RSpec.describe GroupProjectsFinder do describe 'with a group member current user' do before do - group.add_maintainer(current_user) + root_group.add_maintainer(current_user) end context "only shared" do let(:options) { { only_shared: true } } it { is_expected.to match_array([shared_project_3, shared_project_2, shared_project_1]) } + + context 'with ancestor groups projects' do + before do + options[:include_ancestor_groups] = true + end + + it { is_expected.to match_array([shared_project_3, shared_project_2, shared_project_1]) } + end + + context 'with subgroups projects' do + before do + options[:include_subgroups] = true + end + + it { is_expected.to match_array([shared_project_3, shared_project_2, shared_project_1]) } + end end context "only owned" do @@ -29,9 +45,46 @@ RSpec.describe GroupProjectsFinder do it { is_expected.to match_array([private_project, public_project, subgroup_project, subgroup_private_project]) } end - context 'without subgroups projects' do + context 'with ancestor group projects' do + before do + options[:include_ancestor_groups] = true + end + + it { is_expected.to match_array([private_project, public_project, root_group_public_project, root_group_private_project, root_group_private_project_2]) } + end + + context 'with ancestor groups and subgroups projects' do + before do + options[:include_ancestor_groups] = true + options[:include_subgroups] = true + end + + it { is_expected.to match_array([private_project, public_project, root_group_public_project, root_group_private_project, root_group_private_project_2, subgroup_private_project, subgroup_project]) } + end + + context 'without subgroups and ancestor group projects' do it { is_expected.to match_array([private_project, public_project]) } end + + context 'when user is member only of a subgroup' do + let(:subgroup_member) { create(:user) } + + context 'with ancestor groups and subgroups projects' do + before do + group.add_maintainer(subgroup_member) + options[:include_ancestor_groups] = true + options[:include_subgroups] = true + end + + it 'does not return parent group projects' do + finder = described_class.new(group: group, current_user: subgroup_member, params: params, options: options) + + projects = finder.execute + + expect(projects).to match_array([private_project, public_project, subgroup_project, subgroup_private_project, root_group_public_project]) + end + end + end end context "all" do @@ -90,6 +143,7 @@ RSpec.describe GroupProjectsFinder do before do private_project.add_maintainer(current_user) subgroup_private_project.add_maintainer(current_user) + root_group_private_project.add_maintainer(current_user) end context 'with subgroups projects' do @@ -100,6 +154,23 @@ RSpec.describe GroupProjectsFinder do it { is_expected.to match_array([private_project, public_project, subgroup_project, subgroup_private_project]) } end + context 'with ancestor groups projects' do + before do + options[:include_ancestor_groups] = true + end + + it { is_expected.to match_array([private_project, public_project, root_group_public_project, root_group_private_project]) } + end + + context 'with ancestor groups and subgroups projects' do + before do + options[:include_ancestor_groups] = true + options[:include_subgroups] = true + end + + it { is_expected.to match_array([private_project, public_project, root_group_private_project, root_group_public_project, subgroup_private_project, subgroup_project]) } + end + context 'without subgroups projects' do it { is_expected.to match_array([private_project, public_project]) } end @@ -118,6 +189,23 @@ RSpec.describe GroupProjectsFinder do it { is_expected.to match_array([public_project, subgroup_project]) } end + context 'with ancestor groups projects' do + before do + options[:include_ancestor_groups] = true + end + + it { is_expected.to match_array([public_project, root_group_public_project]) } + end + + context 'with ancestor groups and subgroups projects' do + before do + options[:include_subgroups] = true + options[:include_ancestor_groups] = true + end + + it { is_expected.to match_array([public_project, root_group_public_project, subgroup_project]) } + end + context 'without subgroups projects' do it { is_expected.to eq([public_project]) } end diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 31563a6326d..c22e56c3b9e 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -1018,6 +1018,8 @@ RSpec.describe IssuesFinder do end context 'filtering by due date' do + let_it_be(:issue_due_today) { create(:issue, project: project1, due_date: Date.current) } + let_it_be(:issue_due_tomorrow) { create(:issue, project: project1, due_date: 1.day.from_now) } let_it_be(:issue_overdue) { create(:issue, project: project1, due_date: 2.days.ago) } let_it_be(:issue_due_soon) { create(:issue, project: project1, due_date: 2.days.from_now) } @@ -1032,6 +1034,30 @@ RSpec.describe IssuesFinder do end end + context 'with param set to any due date' do + let(:params) { base_params.merge(due_date: Issue::AnyDueDate.name) } + + it 'returns issues with any due date' do + expect(issues).to contain_exactly(issue_due_today, issue_due_tomorrow, issue_overdue, issue_due_soon) + end + end + + context 'with param set to due today' do + let(:params) { base_params.merge(due_date: Issue::DueToday.name) } + + it 'returns issues due today' do + expect(issues).to contain_exactly(issue_due_today) + end + end + + context 'with param set to due tomorrow' do + let(:params) { base_params.merge(due_date: Issue::DueTomorrow.name) } + + it 'returns issues due today' do + expect(issues).to contain_exactly(issue_due_tomorrow) + end + end + context 'with param set to overdue' do let(:params) { base_params.merge(due_date: Issue::Overdue.name) } @@ -1043,8 +1069,8 @@ RSpec.describe IssuesFinder do context 'with param set to next month and previous two weeks' do let(:params) { base_params.merge(due_date: Issue::DueNextMonthAndPreviousTwoWeeks.name) } - it 'returns issues from the previous two weeks and next month' do - expect(issues).to contain_exactly(issue_overdue, issue_due_soon) + it 'returns issues due in the previous two weeks and next month' do + expect(issues).to contain_exactly(issue_due_today, issue_due_tomorrow, issue_overdue, issue_due_soon) end end diff --git a/spec/finders/merge_request_target_project_finder_spec.rb b/spec/finders/merge_request_target_project_finder_spec.rb index 08fbfd7229a..bf735152d99 100644 --- a/spec/finders/merge_request_target_project_finder_spec.rb +++ b/spec/finders/merge_request_target_project_finder_spec.rb @@ -65,8 +65,8 @@ RSpec.describe MergeRequestTargetProjectFinder do context 'private projects' do let(:base_project) { create(:project, :private, path: 'base') } - let(:forked_project) { fork_project(base_project, base_project.owner) } - let(:other_fork) { fork_project(base_project, base_project.owner) } + let(:forked_project) { fork_project(base_project, base_project.first_owner) } + let(:other_fork) { fork_project(base_project, base_project.first_owner) } context 'when the user is a member of all projects' do before do diff --git a/spec/finders/merge_requests_finder/params_spec.rb b/spec/finders/merge_requests_finder/params_spec.rb new file mode 100644 index 00000000000..8c285972f48 --- /dev/null +++ b/spec/finders/merge_requests_finder/params_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MergeRequestsFinder::Params do + let(:user) { create(:user) } + + subject { described_class.new(params, user, MergeRequest) } + + describe 'attention' do + context 'attention param exists' do + let(:params) { { attention: user.username } } + + it { expect(subject.attention).to eq(user) } + end + + context 'attention param does not exist' do + let(:params) { { attention: nil } } + + it { expect(subject.attention).to eq(nil) } + end + end +end diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 0b6c438fd02..1f63f69a411 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -408,6 +408,22 @@ RSpec.describe MergeRequestsFinder do end end + context 'attention' do + subject { described_class.new(user, params).execute } + + before do + reviewer = merge_request1.find_reviewer(user2) + reviewer.update!(state: :reviewed) + end + + context 'by username' do + let(:params) { { attention: user2.username } } + let(:expected_mr) { [merge_request2, merge_request3] } + + it { is_expected.to contain_exactly(*expected_mr) } + end + end + context 'reviewer filtering' do subject { described_class.new(user, params).execute } diff --git a/spec/finders/packages/conan/package_file_finder_spec.rb b/spec/finders/packages/conan/package_file_finder_spec.rb index 3da7da456c2..62906a7b0a9 100644 --- a/spec/finders/packages/conan/package_file_finder_spec.rb +++ b/spec/finders/packages/conan/package_file_finder_spec.rb @@ -49,18 +49,6 @@ RSpec.describe ::Packages::Conan::PackageFileFinder do expect(subject).to eq(package_file) end - - context 'with packages_installable_package_files disabled' do - before do - stub_feature_flags(packages_installable_package_files: false) - end - - it 'returns the correct package file' do - expect(package.package_files.last).to eq(recent_package_file_pending_destruction) - - expect(subject).to eq(recent_package_file_pending_destruction) - end - end end describe '#execute' do diff --git a/spec/finders/packages/package_file_finder_spec.rb b/spec/finders/packages/package_file_finder_spec.rb index 8b21c9cd3ec..711e1396126 100644 --- a/spec/finders/packages/package_file_finder_spec.rb +++ b/spec/finders/packages/package_file_finder_spec.rb @@ -29,16 +29,6 @@ RSpec.describe Packages::PackageFileFinder do expect(subject).to eq(package_file) end - - context 'with packages_installable_package_files disabled' do - before do - stub_feature_flags(packages_installable_package_files: false) - end - - it 'returns them' do - expect(subject).to eq(recent_package_file_pending_destruction) - end - end end describe '#execute' do diff --git a/spec/finders/releases_finder_spec.rb b/spec/finders/releases_finder_spec.rb index 94b6fe53daa..5ddb5c33fad 100644 --- a/spec/finders/releases_finder_spec.rb +++ b/spec/finders/releases_finder_spec.rb @@ -23,6 +23,16 @@ RSpec.describe ReleasesFinder do end end + shared_examples_for 'when the user is not part of the group' do + before do + allow(Ability).to receive(:allowed?).with(user, :read_release, group).and_return(false) + end + + it 'returns no releases' do + is_expected.to be_empty + end + end + # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27716 shared_examples_for 'when tag is nil' do before do @@ -66,9 +76,9 @@ RSpec.describe ReleasesFinder do it_behaves_like 'when the user is not part of the project' - context 'when the user is a project developer' do + context 'when the user is a project guest' do before do - project.add_developer(user) + project.add_guest(user) end it 'sorts by release date' do @@ -118,25 +128,24 @@ RSpec.describe ReleasesFinder do subject { described_class.new(group, user, params).execute(**args) } - it_behaves_like 'when the user is not part of the project' + it_behaves_like 'when the user is not part of the group' - context 'when the user is a project developer on one sibling project' do + context 'when the user is a project guest on one sibling project' do before do - project.add_developer(user) + project.add_guest(user) v1_0_0.update_attribute(:released_at, 3.days.ago) v1_1_0.update_attribute(:released_at, 1.day.ago) end - it 'sorts by release date' do - expect(subject.size).to eq(2) - expect(subject).to eq([v1_1_0, v1_0_0]) + it 'does not return any releases' do + expect(subject.size).to eq(0) + expect(subject).to eq([]) end end - context 'when the user is a project developer on all projects' do + context 'when the user is a guest on the group' do before do - project.add_developer(user) - project2.add_developer(user) + group.add_guest(user) v1_0_0.update_attribute(:released_at, 3.days.ago) v6.update_attribute(:released_at, 2.days.ago) v1_1_0.update_attribute(:released_at, 1.day.ago) @@ -161,22 +170,21 @@ RSpec.describe ReleasesFinder do let(:project2) { create(:project, :repository, namespace: subgroup) } let!(:v6) { create(:release, project: project2, tag: 'v6') } - it_behaves_like 'when the user is not part of the project' + it_behaves_like 'when the user is not part of the group' - context 'when the user a project developer in the subgroup project' do + context 'when the user a project guest in the subgroup project' do before do - project2.add_developer(user) + project2.add_guest(user) end - it 'returns only the subgroup releases' do - expect(subject).to match_array([v6]) + it 'does not return any releases' do + expect(subject).to match_array([]) end end - context 'when the user a project developer in both projects' do + context 'when the user is a guest on the group' do before do - project.add_developer(user) - project2.add_developer(user) + group.add_guest(user) v6.update_attribute(:released_at, 2.days.ago) end @@ -201,34 +209,32 @@ RSpec.describe ReleasesFinder do p3.update_attribute(:released_at, 3.days.ago) end - it_behaves_like 'when the user is not part of the project' + it_behaves_like 'when the user is not part of the group' - context 'when the user a project developer in the subgroup and subsubgroup project' do + context 'when the user a project guest in the subgroup and subsubgroup project' do before do - project2.add_developer(user) - project3.add_developer(user) + project2.add_guest(user) + project3.add_guest(user) end - it 'returns only the subgroup and subsubgroup releases' do - expect(subject).to match_array([v6, p3]) + it 'does not return any releases' do + expect(subject).to match_array([]) end end - context 'when the user a project developer in the subsubgroup project' do + context 'when the user a project guest in the subsubgroup project' do before do - project3.add_developer(user) + project3.add_guest(user) end - it 'returns only the subsubgroup releases' do - expect(subject).to match_array([p3]) + it 'does not return any releases' do + expect(subject).to match_array([]) end end - context 'when the user a project developer in all projects' do + context 'when the user a guest on the group' do before do - project.add_developer(user) - project2.add_developer(user) - project3.add_developer(user) + group.add_guest(user) end it 'returns all releases' do diff --git a/spec/finders/tags_finder_spec.rb b/spec/finders/tags_finder_spec.rb index acc86547271..70d79ced81d 100644 --- a/spec/finders/tags_finder_spec.rb +++ b/spec/finders/tags_finder_spec.rb @@ -32,6 +32,14 @@ RSpec.describe TagsFinder do expect(load_tags(params).first.name).to eq('v1.0.0') end + + context 'when sort is not a string' do + it 'ignores sort parameter' do + params = { sort: { 'invalid' => 'string' } } + + expect(load_tags(params).first.name).to eq('v1.0.0') + end + end end context 'filter only' do @@ -70,6 +78,13 @@ RSpec.describe TagsFinder do result = load_tags({ search: 'nope$' }) expect(result.count).to eq(0) end + + context 'when search is not a string' do + it 'returns no matches' do + result = load_tags({ search: { 'a' => 'b' } }) + expect(result.count).to eq(0) + end + end end context 'filter and sort' do diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb index 97eecf8a89d..8e2426e697b 100644 --- a/spec/finders/template_finder_spec.rb +++ b/spec/finders/template_finder_spec.rb @@ -153,7 +153,12 @@ RSpec.describe TemplateFinder do let(:params) { {} } - subject(:result) { described_class.new(type, project, params).template_names.values.flatten.map { |el| OpenStruct.new(el) } } + let(:template_name_struct) { Struct.new(:name, :id, :key, :project_id, keyword_init: true) } + + subject(:result) do + described_class.new(type, project, params).template_names.values.flatten + .map { |el| template_name_struct.new(el) } + end where(:type, :vendored_name) do :dockerfiles | 'Binary' |