diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
commit | 3b1af5cc7ed2666ff18b718ce5d30fa5a2756674 (patch) | |
tree | 3bc4a40e0ee51ec27eabf917c537033c0c5b14d4 /spec/finders | |
parent | 9bba14be3f2c211bf79e15769cd9b77bc73a13bc (diff) |
Add latest changes from gitlab-org/gitlab@16-1-stable-eev16.1.0-rc42
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/alert_management/http_integrations_finder_spec.rb | 38 | ||||
-rw-r--r-- | spec/finders/clusters/knative_services_finder_spec.rb | 4 | ||||
-rw-r--r-- | spec/finders/deployments_finder_spec.rb | 48 | ||||
-rw-r--r-- | spec/finders/group_members_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/groups/accepting_project_creations_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/groups/accepting_project_shares_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/groups/environment_scopes_finder_spec.rb | 48 | ||||
-rw-r--r-- | spec/finders/groups/user_groups_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/groups_finder_spec.rb | 16 | ||||
-rw-r--r-- | spec/finders/members_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/merge_requests_finder_spec.rb | 1 | ||||
-rw-r--r-- | spec/finders/namespaces/projects_finder_spec.rb | 31 | ||||
-rw-r--r-- | spec/finders/releases/group_releases_finder_spec.rb | 2 | ||||
-rw-r--r-- | spec/finders/releases_finder_spec.rb | 182 | ||||
-rw-r--r-- | spec/finders/template_finder_spec.rb | 17 | ||||
-rw-r--r-- | spec/finders/users_finder_spec.rb | 40 |
16 files changed, 304 insertions, 133 deletions
diff --git a/spec/finders/alert_management/http_integrations_finder_spec.rb b/spec/finders/alert_management/http_integrations_finder_spec.rb index d65de2cdbbd..eb3d24f8653 100644 --- a/spec/finders/alert_management/http_integrations_finder_spec.rb +++ b/spec/finders/alert_management/http_integrations_finder_spec.rb @@ -2,10 +2,12 @@ require 'spec_helper' -RSpec.describe AlertManagement::HttpIntegrationsFinder do +RSpec.describe AlertManagement::HttpIntegrationsFinder, feature_category: :incident_management do let_it_be(:project) { create(:project) } let_it_be_with_reload(:integration) { create(:alert_management_http_integration, project: project ) } let_it_be(:extra_integration) { create(:alert_management_http_integration, project: project ) } + let_it_be(:prometheus_integration) { create(:alert_management_prometheus_integration, :inactive, project: project ) } + let_it_be(:extra_prometheus_integration) { create(:alert_management_prometheus_integration, project: project ) } let_it_be(:alt_project_integration) { create(:alert_management_http_integration) } let(:params) { {} } @@ -14,7 +16,7 @@ RSpec.describe AlertManagement::HttpIntegrationsFinder do subject(:execute) { described_class.new(project, params).execute } context 'empty params' do - it { is_expected.to contain_exactly(integration) } + it { is_expected.to contain_exactly(integration, prometheus_integration) } end context 'endpoint_identifier param given' do @@ -37,7 +39,7 @@ RSpec.describe AlertManagement::HttpIntegrationsFinder do context 'but blank' do let(:params) { { endpoint_identifier: nil } } - it { is_expected.to contain_exactly(integration) } + it { is_expected.to contain_exactly(integration, prometheus_integration) } end end @@ -46,18 +48,34 @@ RSpec.describe AlertManagement::HttpIntegrationsFinder do it { is_expected.to contain_exactly(integration) } - context 'when integration is disabled' do - before do - integration.update!(active: false) - end + context 'but blank' do + let(:params) { { active: nil } } - it { is_expected.to be_empty } + it { is_expected.to contain_exactly(integration, prometheus_integration) } + end + end + + context 'type_identifier param given' do + let(:params) { { type_identifier: extra_integration.type_identifier } } + + it { is_expected.to contain_exactly(integration) } + + context 'matches an unavailable integration' do + let(:params) { { type_identifier: extra_prometheus_integration.type_identifier } } + + it { is_expected.to contain_exactly(prometheus_integration) } + end + + context 'but unknown' do + let(:params) { { type_identifier: :unknown } } + + it { is_expected.to contain_exactly(integration, prometheus_integration) } end context 'but blank' do - let(:params) { { active: nil } } + let(:params) { { type_identifier: nil } } - it { is_expected.to contain_exactly(integration) } + it { is_expected.to contain_exactly(integration, prometheus_integration) } end end diff --git a/spec/finders/clusters/knative_services_finder_spec.rb b/spec/finders/clusters/knative_services_finder_spec.rb index 6f5a4db10e8..7a60364c873 100644 --- a/spec/finders/clusters/knative_services_finder_spec.rb +++ b/spec/finders/clusters/knative_services_finder_spec.rb @@ -7,10 +7,10 @@ RSpec.describe Clusters::KnativeServicesFinder do include ReactiveCachingHelpers let(:project) { create(:project, :repository) } - let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) } + let(:cluster) { deployment.cluster } let(:service) { environment.deployment_platform } let(:environment) { create(:environment, project: project) } - let!(:deployment) { create(:deployment, :success, environment: environment, cluster: cluster) } + let!(:deployment) { create(:deployment, :success, :on_cluster, environment: environment) } let(:namespace) do create(:cluster_kubernetes_namespace, cluster: cluster, diff --git a/spec/finders/deployments_finder_spec.rb b/spec/finders/deployments_finder_spec.rb index 86b6070a368..517fa0e2c7a 100644 --- a/spec/finders/deployments_finder_spec.rb +++ b/spec/finders/deployments_finder_spec.rb @@ -249,53 +249,11 @@ RSpec.describe DeploymentsFinder do end end - describe 'enforce sorting to `updated_at` sorting' do + context 'when `updated_at` is used for filtering without sorting by `updated_at`' do let(:params) { { **base_params, updated_before: 1.day.ago, order_by: 'id', sort: 'asc' } } - context 'when the deployments_raise_updated_at_inefficient_error FF is disabled' do - before do - stub_feature_flags(deployments_raise_updated_at_inefficient_error: false) - end - - it 'sorts by only one column' do - expect(subject.order_values.size).to eq(2) - end - - it 'sorts by `updated_at`' do - expect(subject.order_values.first.to_sql).to eq(Deployment.arel_table[:updated_at].asc.to_sql) - expect(subject.order_values.second.to_sql).to eq(Deployment.arel_table[:id].asc.to_sql) - end - end - - context 'when the deployments_raise_updated_at_inefficient_error FF is enabled' do - before do - stub_feature_flags(deployments_raise_updated_at_inefficient_error: true) - end - - context 'when the flag is overridden' do - before do - stub_feature_flags(deployments_raise_updated_at_inefficient_error_override: true) - end - - it 'sorts by only one column' do - expect(subject.order_values.size).to eq(2) - end - - it 'sorts by `updated_at`' do - expect(subject.order_values.first.to_sql).to eq(Deployment.arel_table[:updated_at].asc.to_sql) - expect(subject.order_values.second.to_sql).to eq(Deployment.arel_table[:id].asc.to_sql) - end - end - - context 'when the flag is not overridden' do - before do - stub_feature_flags(deployments_raise_updated_at_inefficient_error_override: false) - end - - it 'raises an error' do - expect { subject }.to raise_error(DeploymentsFinder::InefficientQueryError) - end - end + it 'raises an error' do + expect { subject }.to raise_error(DeploymentsFinder::InefficientQueryError) end end diff --git a/spec/finders/group_members_finder_spec.rb b/spec/finders/group_members_finder_spec.rb index 4fc49289fa4..4ac4dc3ba37 100644 --- a/spec/finders/group_members_finder_spec.rb +++ b/spec/finders/group_members_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GroupMembersFinder, '#execute', feature_category: :subgroups do +RSpec.describe GroupMembersFinder, '#execute', feature_category: :groups_and_projects do let_it_be(:group) { create(:group) } let_it_be(:sub_group) { create(:group, parent: group) } let_it_be(:sub_sub_group) { create(:group, parent: sub_group) } diff --git a/spec/finders/groups/accepting_project_creations_finder_spec.rb b/spec/finders/groups/accepting_project_creations_finder_spec.rb index 2ea5577dd90..61d673d6a99 100644 --- a/spec/finders/groups/accepting_project_creations_finder_spec.rb +++ b/spec/finders/groups/accepting_project_creations_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Groups::AcceptingProjectCreationsFinder, feature_category: :subgroups do +RSpec.describe Groups::AcceptingProjectCreationsFinder, feature_category: :groups_and_projects do let_it_be(:user) { create(:user) } let_it_be(:group_where_direct_owner) { create(:group) } let_it_be(:subgroup_of_group_where_direct_owner) { create(:group, parent: group_where_direct_owner) } diff --git a/spec/finders/groups/accepting_project_shares_finder_spec.rb b/spec/finders/groups/accepting_project_shares_finder_spec.rb index 6af3fad2110..f5fd865cf4d 100644 --- a/spec/finders/groups/accepting_project_shares_finder_spec.rb +++ b/spec/finders/groups/accepting_project_shares_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Groups::AcceptingProjectSharesFinder, feature_category: :subgroups do +RSpec.describe Groups::AcceptingProjectSharesFinder, feature_category: :groups_and_projects do subject(:result) { described_class.new(current_user, project, params).execute } let_it_be_with_reload(:current_user) { create(:user) } diff --git a/spec/finders/groups/environment_scopes_finder_spec.rb b/spec/finders/groups/environment_scopes_finder_spec.rb new file mode 100644 index 00000000000..dfa32725e4a --- /dev/null +++ b/spec/finders/groups/environment_scopes_finder_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Groups::EnvironmentScopesFinder, feature_category: :secrets_management do + describe '#execute' do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group, :public) } + + let!(:environment1) { create(:ci_group_variable, group: group, key: 'var1', environment_scope: 'environment1') } + let!(:environment2) { create(:ci_group_variable, group: group, key: 'var2', environment_scope: 'environment2') } + let!(:environment3) { create(:ci_group_variable, group: group, key: 'var2', environment_scope: 'environment3') } + let(:finder) { described_class.new(group: group, params: params) } + + subject { finder.execute } + + context 'with default no arguments' do + let(:params) { {} } + + it do + expected_result = group.variables.environment_scope_names + + expect(subject.map(&:name)) + .to match_array(expected_result) + end + end + + context 'with search' do + let(:params) { { search: 'ment1' } } + + it do + expected_result = ['environment1'] + + expect(subject.map(&:name)) + .to match_array(expected_result) + end + end + + context 'with specific name' do + let(:params) { { name: 'environment3' } } + + it do + expect(subject.map(&:name)) + .to match_array([environment3.environment_scope]) + end + end + end +end diff --git a/spec/finders/groups/user_groups_finder_spec.rb b/spec/finders/groups/user_groups_finder_spec.rb index f6df396037c..99974896311 100644 --- a/spec/finders/groups/user_groups_finder_spec.rb +++ b/spec/finders/groups/user_groups_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Groups::UserGroupsFinder, feature_category: :subgroups do +RSpec.describe Groups::UserGroupsFinder, feature_category: :groups_and_projects do describe '#execute' do let_it_be(:user) { create(:user) } let_it_be(:root_group) { create(:group, name: 'Root group', path: 'root-group') } diff --git a/spec/finders/groups_finder_spec.rb b/spec/finders/groups_finder_spec.rb index 25f9331005d..23d73b48199 100644 --- a/spec/finders/groups_finder_spec.rb +++ b/spec/finders/groups_finder_spec.rb @@ -2,10 +2,10 @@ require 'spec_helper' -RSpec.describe GroupsFinder do +RSpec.describe GroupsFinder, feature_category: :groups_and_projects do include AdminModeHelper - shared_examples '#execute' do + describe '#execute' do let(:user) { create(:user) } describe 'root level groups' do @@ -376,16 +376,4 @@ RSpec.describe GroupsFinder do end end end - - describe '#execute' do - include_examples '#execute' - - context 'when use_traversal_ids_groups_finder feature flags is disabled' do - before do - stub_feature_flags(use_traversal_ids_groups_finder: false) - end - - include_examples '#execute' - end - end end diff --git a/spec/finders/members_finder_spec.rb b/spec/finders/members_finder_spec.rb index afab4514ce2..4df6197e3b0 100644 --- a/spec/finders/members_finder_spec.rb +++ b/spec/finders/members_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MembersFinder, feature_category: :subgroups do +RSpec.describe MembersFinder, feature_category: :groups_and_projects do shared_examples '#execute' do let_it_be(:group) { create(:group) } let_it_be(:nested_group) { create(:group, parent: group) } diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 6d576bc8e38..9aa98189f30 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -295,7 +295,6 @@ RSpec.describe MergeRequestsFinder, feature_category: :code_review_workflow do end { - wip: ["WIP:", "wip", "[wip]"], draft: ["Draft:", "Draft -", "[Draft]", "(Draft)"] }.each do |draft_param_key, title_prefixes| title_prefixes.each do |title_prefix| diff --git a/spec/finders/namespaces/projects_finder_spec.rb b/spec/finders/namespaces/projects_finder_spec.rb index 040cdf33b87..9291572d8d1 100644 --- a/spec/finders/namespaces/projects_finder_spec.rb +++ b/spec/finders/namespaces/projects_finder_spec.rb @@ -10,6 +10,8 @@ RSpec.describe Namespaces::ProjectsFinder do let_it_be(:project_2) { create(:project, :public, group: namespace, path: 'test-project', name: 'Test Project') } let_it_be(:project_3) { create(:project, :public, :issues_disabled, path: 'sub-test-project', group: subgroup, name: 'Sub Test Project') } let_it_be(:project_4) { create(:project, :public, :merge_requests_disabled, path: 'test-project-2', group: namespace, name: 'Test Project 2') } + let_it_be(:project_5) { create(:project, group: subgroup, marked_for_deletion_at: 1.day.ago, pending_delete: true) } + let_it_be(:project_6) { create(:project, group: namespace, marked_for_deletion_at: 1.day.ago, pending_delete: true) } let(:params) { {} } @@ -28,14 +30,22 @@ RSpec.describe Namespaces::ProjectsFinder do context 'with a namespace' do it 'returns the project for the namespace' do - expect(projects).to contain_exactly(project_1, project_2, project_4) + expect(projects).to contain_exactly(project_1, project_2, project_4, project_6) + end + + context 'when not_aimed_for_deletion is provided' do + let(:params) { { not_aimed_for_deletion: true } } + + it 'returns all projects not aimed for deletion for the namespace' do + expect(projects).to contain_exactly(project_1, project_2, project_4) + end end context 'when include_subgroups is provided' do let(:params) { { include_subgroups: true } } it 'returns all projects for the namespace' do - expect(projects).to contain_exactly(project_1, project_2, project_3, project_4) + expect(projects).to contain_exactly(project_1, project_2, project_3, project_4, project_5, project_6) end context 'when ids are provided' do @@ -45,6 +55,14 @@ RSpec.describe Namespaces::ProjectsFinder do expect(projects).to contain_exactly(project_3) end end + + context 'when not_aimed_for_deletion is provided' do + let(:params) { { not_aimed_for_deletion: true, include_subgroups: true } } + + it 'returns all projects not aimed for deletion for the namespace' do + expect(projects).to contain_exactly(project_1, project_2, project_3, project_4) + end + end end context 'when ids are provided' do @@ -59,7 +77,7 @@ RSpec.describe Namespaces::ProjectsFinder do let(:params) { { with_issues_enabled: true, include_subgroups: true } } it 'returns the projects that have issues enabled' do - expect(projects).to contain_exactly(project_1, project_2, project_4) + expect(projects).to contain_exactly(project_1, project_2, project_4, project_5, project_6) end end @@ -67,7 +85,7 @@ RSpec.describe Namespaces::ProjectsFinder do let(:params) { { with_merge_requests_enabled: true } } it 'returns the projects that have merge requests enabled' do - expect(projects).to contain_exactly(project_1, project_2) + expect(projects).to contain_exactly(project_1, project_2, project_6) end end @@ -83,7 +101,7 @@ RSpec.describe Namespaces::ProjectsFinder do let(:params) { { sort: :similarity } } it 'returns all projects' do - expect(projects).to contain_exactly(project_1, project_2, project_4) + expect(projects).to contain_exactly(project_1, project_2, project_4, project_6) end end @@ -99,13 +117,14 @@ RSpec.describe Namespaces::ProjectsFinder do let(:params) { { sort: :latest_activity_desc } } before do + project_6.update!(last_activity_at: 15.minutes.ago) project_2.update!(last_activity_at: 10.minutes.ago) project_1.update!(last_activity_at: 5.minutes.ago) project_4.update!(last_activity_at: 1.minute.ago) end it 'returns projects sorted by latest activity' do - expect(projects).to eq([project_4, project_1, project_2]) + expect(projects).to eq([project_4, project_1, project_2, project_6]) end end end diff --git a/spec/finders/releases/group_releases_finder_spec.rb b/spec/finders/releases/group_releases_finder_spec.rb index c47477eb3d5..daefc94828b 100644 --- a/spec/finders/releases/group_releases_finder_spec.rb +++ b/spec/finders/releases/group_releases_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Releases::GroupReleasesFinder, feature_category: :subgroups do +RSpec.describe Releases::GroupReleasesFinder, feature_category: :groups_and_projects do let(:user) { create(:user) } let(:group) { create(:group) } let(:project) { create(:project, :repository, group: group) } diff --git a/spec/finders/releases_finder_spec.rb b/spec/finders/releases_finder_spec.rb index 858a0e566f6..bee0ae0d5c1 100644 --- a/spec/finders/releases_finder_spec.rb +++ b/spec/finders/releases_finder_spec.rb @@ -2,32 +2,17 @@ require 'spec_helper' -RSpec.describe ReleasesFinder do - let(:user) { create(:user) } - let(:group) { create :group } - let(:project) { create(:project, :repository, group: group) } +RSpec.describe ReleasesFinder, feature_category: :release_orchestration do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create :group } + let_it_be(:project) { create(:project, :repository, group: group) } let(:params) { {} } let(:args) { {} } let(:repository) { project.repository } - let(:v1_0_0) { create(:release, project: project, tag: 'v1.0.0') } - let(:v1_1_0) { create(:release, project: project, tag: 'v1.1.0') } - - before do - v1_0_0.update_attribute(:released_at, 2.days.ago) - v1_1_0.update_attribute(:released_at, 1.day.ago) - end - - shared_examples_for 'when the user is not part of the project' do - it 'returns no releases' do - is_expected.to be_empty - 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 + let_it_be(:v1_0_0) { create(:release, project: project, tag: 'v1.0.0') } + let_it_be(:v1_1_0) { create(:release, project: project, tag: 'v1.1.0') } + shared_examples_for 'when the user is not authorized' do it 'returns no releases' do is_expected.to be_empty end @@ -62,26 +47,25 @@ RSpec.describe ReleasesFinder do describe 'when parent is a project' do subject { described_class.new(project, user, params).execute(**args) } - it_behaves_like 'when the user is not part of the project' + it_behaves_like 'when the user is not authorized' - context 'when the user is a project guest' do + context 'when the user has guest privileges or higher' do before do project.add_guest(user) + + v1_0_0.update!(released_at: 2.days.ago, created_at: 1.day.ago) + v1_1_0.update!(released_at: 1.day.ago, created_at: 2.days.ago) end - it 'sorts by release date' do + it 'returns the releases' do is_expected.to be_present expect(subject.size).to eq(2) - expect(subject).to eq([v1_1_0, v1_0_0]) + expect(subject).to match_array([v1_1_0, v1_0_0]) end context 'with sorting parameters' do - before do - v1_1_0.update_attribute(:created_at, 3.days.ago) - end - - context 'by default is released_at in descending order' do - it { is_expected.to eq([v1_1_0, v1_0_0]) } + it 'sorted by released_at in descending order by default' do + is_expected.to eq([v1_1_0, v1_0_0]) end context 'released_at in ascending order' do @@ -107,4 +91,138 @@ RSpec.describe ReleasesFinder do it_behaves_like 'when a tag parameter is passed' end end + + describe 'when parent is an array of projects' do + let_it_be(:project2) { create(:project, :repository, group: group) } + let_it_be(:v2_0_0) { create(:release, project: project2, tag: 'v2.0.0') } + let_it_be(:v2_1_0) { create(:release, project: project2, tag: 'v2.1.0') } + + subject { described_class.new([project, project2], user, params).execute(**args) } + + it_behaves_like 'when the user is not authorized' + + context 'when the user has guest privileges or higher on one project' do + before do + project.add_guest(user) + end + + it 'returns the releases of only the authorized project' do + is_expected.to be_present + expect(subject.size).to eq(2) + expect(subject).to match_array([v1_1_0, v1_0_0]) + end + end + + context 'when the user has guest privileges or higher on all projects' do + before do + project.add_guest(user) + project2.add_guest(user) + + v1_0_0.update!(released_at: 4.days.ago, created_at: 1.day.ago) + v1_1_0.update!(released_at: 3.days.ago, created_at: 2.days.ago) + v2_0_0.update!(released_at: 2.days.ago, created_at: 3.days.ago) + v2_1_0.update!(released_at: 1.day.ago, created_at: 4.days.ago) + end + + it 'returns the releases of all projects' do + is_expected.to be_present + expect(subject.size).to eq(4) + expect(subject).to match_array([v2_1_0, v2_0_0, v1_1_0, v1_0_0]) + end + + it_behaves_like 'preload' + it_behaves_like 'when a tag parameter is passed' + + context 'with sorting parameters' do + it 'sorted by released_at in descending order by default' do + is_expected.to eq([v2_1_0, v2_0_0, v1_1_0, v1_0_0]) + end + + context 'released_at in ascending order' do + let(:params) { { sort: 'asc' } } + + it { is_expected.to eq([v1_0_0, v1_1_0, v2_0_0, v2_1_0]) } + end + + context 'order by created_at in descending order' do + let(:params) { { order_by: 'created_at' } } + + it { is_expected.to eq([v1_0_0, v1_1_0, v2_0_0, v2_1_0]) } + end + + context 'order by created_at in ascending order' do + let(:params) { { order_by: 'created_at', sort: 'asc' } } + + it { is_expected.to eq([v2_1_0, v2_0_0, v1_1_0, v1_0_0]) } + end + end + end + end + + describe 'latest releases' do + let_it_be(:project2) { create(:project, :repository, group: group) } + let_it_be(:v2_0_0) { create(:release, project: project2) } + let_it_be(:v2_1_0) { create(:release, project: project2) } + + let(:params) { { latest: true } } + + subject { described_class.new([project, project2], user, params).execute(**args) } + + before do + v1_0_0.update!(released_at: 4.days.ago, created_at: 1.day.ago) + v1_1_0.update!(released_at: 3.days.ago, created_at: 2.days.ago) + v2_0_0.update!(released_at: 2.days.ago, created_at: 3.days.ago) + v2_1_0.update!(released_at: 1.day.ago, created_at: 4.days.ago) + end + + it_behaves_like 'when the user is not authorized' + + context 'when the user has guest privileges or higher on one project' do + before do + project.add_guest(user) + end + + it 'returns the latest release of only the authorized project' do + is_expected.to eq([v1_1_0]) + end + end + + context 'when the user has guest privileges or higher on all projects' do + before do + project.add_guest(user) + project2.add_guest(user) + end + + it 'returns the latest release by released date for each project' do + is_expected.to match_array([v1_1_0, v2_1_0]) + end + + context 'with order_by_for_latest: created' do + let(:params) { { latest: true, order_by_for_latest: 'created_at' } } + + it 'returns the latest release by created date for each project' do + is_expected.to match_array([v1_0_0, v2_0_0]) + end + end + + context 'when one project does not have releases' do + it 'returns the latest release of only the project with releases' do + project.releases.delete_all + + is_expected.to eq([v2_1_0]) + end + end + + context 'when all projects do not have releases' do + it 'returns empty response' do + project.releases.delete_all + project2.releases.delete_all + + is_expected.to be_empty + end + end + + it_behaves_like 'preload' + end + end end diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb index c466f533a61..eacce0bd996 100644 --- a/spec/finders/template_finder_spec.rb +++ b/spec/finders/template_finder_spec.rb @@ -20,7 +20,6 @@ RSpec.describe TemplateFinder do :dockerfiles | 'Binary' :gitignores | 'Actionscript' :gitlab_ci_ymls | 'Android' - :metrics_dashboard_ymls | 'Default' end with_them do @@ -103,16 +102,11 @@ RSpec.describe TemplateFinder do describe '#build' do let(:project) { build_stubbed(:project) } - before do - stub_feature_flags(remove_monitor_metrics: false) - end - where(:type, :expected_class) do :dockerfiles | described_class :gitignores | described_class :gitlab_ci_ymls | described_class :licenses | ::LicenseTemplateFinder - :metrics_dashboard_ymls | described_class :issues | described_class :merge_requests | described_class end @@ -123,16 +117,6 @@ RSpec.describe TemplateFinder do it { is_expected.to be_a(expected_class) } it { expect(finder.project).to eq(project) } end - - context 'when metrics dashboard is unavailable' do - before do - stub_feature_flags(remove_monitor_metrics: true) - end - - subject(:finder) { described_class.build(:metrics_dashboard_ymls, project) } - - it { is_expected.to be_nil } - end end describe '#execute' do @@ -178,7 +162,6 @@ RSpec.describe TemplateFinder do :dockerfiles | 'Binary' :gitignores | 'Actionscript' :gitlab_ci_ymls | 'Android' - :metrics_dashboard_ymls | 'Default' end with_them do diff --git a/spec/finders/users_finder_spec.rb b/spec/finders/users_finder_spec.rb index 2e94ca5757a..e0a9237a79b 100644 --- a/spec/finders/users_finder_spec.rb +++ b/spec/finders/users_finder_spec.rb @@ -45,6 +45,46 @@ RSpec.describe UsersFinder do expect(users).to be_empty end + describe 'minimum character limit for search' do + it 'passes use_minimum_char_limit from params' do + search_term = normal_user.username[..1] + expect(User).to receive(:search) + .with(search_term, use_minimum_char_limit: false, with_private_emails: anything) + .once.and_call_original + + described_class.new(user, { search: search_term, use_minimum_char_limit: false }).execute + end + + it 'allows searching with 2 characters when use_minimum_char_limit is false' do + users = described_class + .new(user, { search: normal_user.username[..1], use_minimum_char_limit: false }) + .execute + + expect(users).to include(normal_user) + end + + it 'does not allow searching with 2 characters when use_minimum_char_limit is not set' do + users = described_class + .new(user, search: normal_user.username[..1]) + .execute + + expect(users).to be_empty + end + + context 'when autocomplete_users_use_search_service feature flag is disabled' do + before do + stub_feature_flags(autocomplete_users_use_search_service: false) + end + + it 'does not pass use_minimum_char_limit from params' do + search_term = normal_user.username[..1] + expect(User).to receive(:search).with(search_term, with_private_emails: anything).once.and_call_original + + described_class.new(user, { search: search_term, use_minimum_char_limit: false }).execute + end + end + end + it 'filters by external users' do users = described_class.new(user, external: true).execute |