diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-11 18:10:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-11 18:10:00 +0300 |
commit | d06e4d855aed9148571c7fd95fe02f208a017dd3 (patch) | |
tree | 83a1fe4bc449255b426f6b87fa4a37732a5c1fa1 /spec | |
parent | 320d8adff14c100cd8a6798880b7eeff8e137f15 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/ci/jobs_finder_spec.rb | 38 | ||||
-rw-r--r-- | spec/finders/groups/accepting_group_transfers_finder_spec.rb | 33 | ||||
-rw-r--r-- | spec/finders/packages/npm/packages_for_user_finder_spec.rb | 41 | ||||
-rw-r--r-- | spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/sql/pattern_spec.rb | 46 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 17 | ||||
-rw-r--r-- | spec/requests/api/npm_group_packages_spec.rb | 37 | ||||
-rw-r--r-- | spec/requests/api/npm_instance_packages_spec.rb | 29 | ||||
-rw-r--r-- | spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb | 64 | ||||
-rw-r--r-- | spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb | 4 |
10 files changed, 217 insertions, 110 deletions
diff --git a/spec/finders/ci/jobs_finder_spec.rb b/spec/finders/ci/jobs_finder_spec.rb index e86ac65df61..57046baafab 100644 --- a/spec/finders/ci/jobs_finder_spec.rb +++ b/spec/finders/ci/jobs_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::JobsFinder, '#execute', feature_category: :runner_fleet do +RSpec.describe Ci::JobsFinder, '#execute', feature_category: :continuous_integration do let_it_be(:user) { create(:user) } let_it_be(:admin) { create(:user, :admin) } let_it_be(:project) { create(:project, :private, public_builds: false) } @@ -13,8 +13,8 @@ RSpec.describe Ci::JobsFinder, '#execute', feature_category: :runner_fleet do let(:params) { {} } - context 'when project, pipeline or runner are blank' do - subject { described_class.new(current_user: current_user, params: params).execute } + context 'when project, pipeline, and runner are blank' do + subject(:finder_execute) { described_class.new(current_user: current_user, params: params).execute } context 'with admin' do let(:current_user) { admin } @@ -278,28 +278,30 @@ RSpec.describe Ci::JobsFinder, '#execute', feature_category: :runner_fleet 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 } + subject(:execute) { described_class.new(current_user: user, runner: runner, params: params).execute } - context 'with admin and admin mode enabled', :enable_admin_mode do + context 'when current user is an admin' do let(:user) { admin } - it 'returns jobs for the specified project' do - expect(subject).to match_array([job_4]) - end + context 'when admin mode is enabled', :enable_admin_mode do + it 'returns jobs for the specified project' do + expect(subject).to contain_exactly job_4 + end - context "with params" do - using RSpec::Parameterized::TableSyntax + context 'with params' do + using RSpec::Parameterized::TableSyntax - where(:param_runner_type, :param_scope, :expected_jobs) do - 'project_type' | 'success' | lazy { [job_4] } - 'instance_type' | nil | lazy { [] } - nil | 'pending' | lazy { [] } - end + where(:param_runner_type, :param_scope, :expected_jobs) do + 'project_type' | 'success' | lazy { [job_4] } + 'instance_type' | nil | lazy { [] } + nil | 'pending' | lazy { [] } + end - with_them do - let(:params) { { runner_type: param_runner_type, scope: param_scope } } + with_them do + let(:params) { { runner_type: param_runner_type, scope: param_scope } } - it { is_expected.to match_array(expected_jobs) } + it { is_expected.to match_array(expected_jobs) } + end end end end diff --git a/spec/finders/groups/accepting_group_transfers_finder_spec.rb b/spec/finders/groups/accepting_group_transfers_finder_spec.rb index 18407dd0196..2a61150acf9 100644 --- a/spec/finders/groups/accepting_group_transfers_finder_spec.rb +++ b/spec/finders/groups/accepting_group_transfers_finder_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Groups::AcceptingGroupTransfersFinder do +RSpec.describe Groups::AcceptingGroupTransfersFinder, feature_category: :groups_and_projects do let_it_be(:current_user) { create(:user) } let_it_be(:great_grandparent_group) do @@ -119,6 +119,37 @@ RSpec.describe Groups::AcceptingGroupTransfersFinder do expect(result).to contain_exactly(great_grandparent_group) end end + + context 'on searching with multiple matches' do + let(:params) { { search: 'great-grandparent-group' } } + let(:other_groups) { [] } + + before do + 2.times do + # app/finders/group/base.rb adds an ORDER BY path, so create a group with 1 in the front. + group = create(:group, parent: great_grandparent_group, path: "1-#{SecureRandom.hex}") + group.add_owner(current_user) + other_groups << group + end + end + + it 'prioritizes exact matches first' do + expect(result.first).to eq(great_grandparent_group) + expect(result[1..]).to match_array(other_groups) + end + + context 'when exact_matches_first_group_transfer feature flag is disabled' do + let(:expected_groups) { other_groups + [great_grandparent_group] } + + before do + stub_feature_flags(exact_matches_first_group_transfer: false) + end + + it 'returns matching groups sorted by namespace path' do + expect(result).to match_array(expected_groups.sort_by(&:path)) + end + end + end end end end diff --git a/spec/finders/packages/npm/packages_for_user_finder_spec.rb b/spec/finders/packages/npm/packages_for_user_finder_spec.rb new file mode 100644 index 00000000000..e2dc21e1008 --- /dev/null +++ b/spec/finders/packages/npm/packages_for_user_finder_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Packages::Npm::PackagesForUserFinder, feature_category: :package_registry do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:project2) { create(:project, group: group) } + let_it_be(:package) { create(:npm_package, project: project) } + let_it_be(:package_name) { package.name } + let_it_be(:package_with_diff_name) { create(:npm_package, project: project) } + let_it_be(:package_with_diff_project) { create(:npm_package, name: package_name, project: project2) } + let_it_be(:maven_package) { create(:maven_package, name: package_name, project: project) } + + let(:finder) { described_class.new(user, project_or_group, package_name: package_name) } + + describe '#execute' do + subject { finder.execute } + + shared_examples 'searches for packages' do + it { is_expected.to contain_exactly(package) } + end + + context 'with a project' do + let(:project_or_group) { project } + + it_behaves_like 'searches for packages' + end + + context 'with a group' do + let(:project_or_group) { group } + + before_all do + project.add_reporter(user) + end + + it_behaves_like 'searches for packages' + end + end +end diff --git a/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb b/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb index 933abf31470..6b9e3a484b1 100644 --- a/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb @@ -5,6 +5,7 @@ require 'spec_helper' RSpec.describe Resolvers::Ci::AllJobsResolver, feature_category: :continuous_integration do include GraphqlHelpers + let_it_be(:instance_runner) { create(:ci_runner, :instance) } let_it_be(:successful_job) { create(:ci_build, :success, name: 'successful_job') } let_it_be(:successful_job_two) { create(:ci_build, :success, name: 'successful_job_two') } let_it_be(:failed_job) { create(:ci_build, :failed, name: 'failed_job') } @@ -12,11 +13,11 @@ RSpec.describe Resolvers::Ci::AllJobsResolver, feature_category: :continuous_int let(:args) { {} } - subject { resolve_jobs(args) } - describe '#resolve' do - context 'with admin' do - let(:current_user) { create(:admin) } + subject(:request) { resolve_jobs(args) } + + context 'when current user is an admin' do + let_it_be(:current_user) { create(:admin) } shared_examples 'executes as admin' do context "with argument `statuses`" do @@ -40,8 +41,7 @@ RSpec.describe Resolvers::Ci::AllJobsResolver, feature_category: :continuous_int context "with argument `runner_types`" do let_it_be(:successful_job_with_instance_runner) do - create(:ci_build, :success, name: 'successful_job_with_instance_runner', - runner: create(:ci_runner, :instance)) + create(:ci_build, :success, name: 'successful_job_with_instance_runner', runner: instance_runner) end context 'with feature flag :admin_jobs_filter_runner_type enabled' do @@ -80,7 +80,7 @@ RSpec.describe Resolvers::Ci::AllJobsResolver, feature_category: :continuous_int :ci_build, :success, name: 'successful_job_with_instance_runner', - runner: create(:ci_runner, :instance) + runner: instance_runner ) end @@ -132,7 +132,9 @@ RSpec.describe Resolvers::Ci::AllJobsResolver, feature_category: :continuous_int end context 'with unauthorized user' do - let(:current_user) { nil } + let_it_be(:unauth_user) { create(:user) } + + let(:current_user) { unauth_user } it { is_expected.to be_empty } end diff --git a/spec/lib/gitlab/sql/pattern_spec.rb b/spec/lib/gitlab/sql/pattern_spec.rb index a34ddf8773c..7bd2ddf2889 100644 --- a/spec/lib/gitlab/sql/pattern_spec.rb +++ b/spec/lib/gitlab/sql/pattern_spec.rb @@ -9,36 +9,44 @@ RSpec.describe Gitlab::SQL::Pattern do let_it_be(:issue1) { create(:issue, title: 'noise foo noise', description: 'noise bar noise') } let_it_be(:issue2) { create(:issue, title: 'noise baz noise', description: 'noise foo noise') } let_it_be(:issue3) { create(:issue, title: 'Oh', description: 'Ah') } + let_it_be(:issue4) { create(:issue, title: 'beep beep', description: 'beep beep') } + let_it_be(:issue5) { create(:issue, title: 'beep', description: 'beep') } - subject(:fuzzy_search) { Issue.fuzzy_search(query, columns) } + subject(:fuzzy_search) { Issue.fuzzy_search(query, columns, exact_matches_first: exact_matches_first) } - where(:query, :columns, :expected) do - 'foo' | [Issue.arel_table[:title]] | %i[issue1] + where(:query, :columns, :exact_matches_first, :expected) do + 'foo' | [Issue.arel_table[:title]] | false | %i[issue1] - 'foo' | %i[title] | %i[issue1] - 'foo' | %w[title] | %i[issue1] - 'foo' | %i[description] | %i[issue2] - 'foo' | %i[title description] | %i[issue1 issue2] - 'bar' | %i[title description] | %i[issue1] - 'baz' | %i[title description] | %i[issue2] - 'qux' | %i[title description] | [] + 'foo' | %i[title] | false | %i[issue1] + 'foo' | %w[title] | false | %i[issue1] + 'foo' | %i[description] | false | %i[issue2] + 'foo' | %i[title description] | false | %i[issue1 issue2] + 'bar' | %i[title description] | false | %i[issue1] + 'baz' | %i[title description] | false | %i[issue2] + 'qux' | %i[title description] | false | [] - 'oh' | %i[title description] | %i[issue3] - 'OH' | %i[title description] | %i[issue3] - 'ah' | %i[title description] | %i[issue3] - 'AH' | %i[title description] | %i[issue3] - 'oh' | %i[title] | %i[issue3] - 'ah' | %i[description] | %i[issue3] + 'oh' | %i[title description] | false | %i[issue3] + 'OH' | %i[title description] | false | %i[issue3] + 'ah' | %i[title description] | false | %i[issue3] + 'AH' | %i[title description] | false | %i[issue3] + 'oh' | %i[title] | false | %i[issue3] + 'ah' | %i[description] | false | %i[issue3] - '' | %i[title] | %i[issue1 issue2 issue3] - %w[a b] | %i[title] | %i[issue1 issue2 issue3] + '' | %i[title] | false | %i[issue1 issue2 issue3 issue4 issue5] + %w[a b] | %i[title] | false | %i[issue1 issue2 issue3 issue4 issue5] + + 'beep' | %i[title] | true | %i[issue5 issue4] end with_them do let(:expected_issues) { expected.map { |sym| send(sym) } } it 'finds the expected issues' do - expect(fuzzy_search).to match_array(expected_issues) + if exact_matches_first + expect(fuzzy_search).to eq(expected_issues) + else + expect(fuzzy_search).to match_array(expected_issues) + end end end end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index a03dac83113..37d967cbc7c 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -1079,17 +1079,30 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do end it 'defaults use_minimum_char_limit to true' do - expect(described_class).to receive(:fuzzy_search).with(anything, anything, use_minimum_char_limit: true).once + expect(described_class).to receive(:fuzzy_search).with(anything, anything, use_minimum_char_limit: true, exact_matches_first: false).once described_class.search('my namespace') end it 'passes use_minimum_char_limit if it is set' do - expect(described_class).to receive(:fuzzy_search).with(anything, anything, use_minimum_char_limit: false).once + expect(described_class).to receive(:fuzzy_search).with(anything, anything, use_minimum_char_limit: false, exact_matches_first: false).once described_class.search('my namespace', use_minimum_char_limit: false) end + context 'with multiple matching namespaces' do + let_it_be(:first_group) { create(:group, name: 'some name', path: 'z-path') } + let_it_be(:second_group) { create(:group, name: 'some name too', path: 'a-path') } + + it 'returns exact matches first' do + expect(described_class.search('some name', exact_matches_first: true).to_a).to eq([first_group, second_group]) + end + + it 'returns exact matches first when parents are included' do + expect(described_class.search('some name', include_parents: true, exact_matches_first: true).to_a).to eq([first_group, second_group]) + end + end + context 'with project namespaces' do let_it_be(:project) { create(:project, namespace: parent_group, path: 'some-new-path') } let_it_be(:project_namespace) { project.project_namespace } diff --git a/spec/requests/api/npm_group_packages_spec.rb b/spec/requests/api/npm_group_packages_spec.rb index 6968e30e2b0..7fba75b0630 100644 --- a/spec/requests/api/npm_group_packages_spec.rb +++ b/spec/requests/api/npm_group_packages_spec.rb @@ -11,43 +11,12 @@ RSpec.describe API::NpmGroupPackages, feature_category: :package_registry do let(:url) { api("/groups/#{group.id}/-/packages/npm/#{package_name}") } it_behaves_like 'handling get metadata requests', scope: :group - - context 'with a duplicate package name in another project' do + it_behaves_like 'rejects invalid package names' do subject { get(url) } - - before do - group.add_developer(user) - end - - let_it_be(:project2) { create(:project, :public, namespace: namespace) } - let_it_be(:package2) do - create(:npm_package, - project: project2, - name: "@#{group.path}/scoped_package", - version: '1.2.0') - end - - it_behaves_like 'rejects invalid package names' - - it 'includes all matching package versions in the response' do - subject - - expect(json_response['versions'].keys).to match_array([package.version, package2.version]) - end - - context 'with the feature flag disabled' do - before do - stub_feature_flags(npm_allow_packages_in_multiple_projects: false) - end - - it 'returns matching package versions from only one project' do - subject - - expect(json_response['versions'].keys).to match_array([package2.version]) - end - end end + it_behaves_like 'handling get metadata requests for packages in multiple projects' + context 'with mixed group and project visibilities' do subject { get(url, headers: headers) } diff --git a/spec/requests/api/npm_instance_packages_spec.rb b/spec/requests/api/npm_instance_packages_spec.rb index 4f965d86d66..7b74a052860 100644 --- a/spec/requests/api/npm_instance_packages_spec.rb +++ b/spec/requests/api/npm_instance_packages_spec.rb @@ -17,34 +17,7 @@ RSpec.describe API::NpmInstancePackages, feature_category: :package_registry do it_behaves_like 'handling get metadata requests', scope: :instance it_behaves_like 'rejects invalid package names' - - context 'with a duplicate package name in another project' do - let_it_be(:project2) { create(:project, :public, namespace: namespace) } - let_it_be(:package2) do - create(:npm_package, - project: project2, - name: "@#{group.path}/scoped_package", - version: '1.2.0') - end - - it 'includes all matching package versions in the response' do - subject - - expect(json_response['versions'].keys).to match_array([package.version, package2.version]) - end - - context 'with the feature flag disabled' do - before do - stub_feature_flags(npm_allow_packages_in_multiple_projects: false) - end - - it 'returns matching package versions from only one project' do - subject - - expect(json_response['versions'].keys).to match_array([package2.version]) - end - end - end + it_behaves_like 'handling get metadata requests for packages in multiple projects' context 'when metadata cache exists' do let_it_be(:npm_metadata_cache) { create(:npm_metadata_cache, package_name: package.name, project_id: project.id) } diff --git a/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb index db547fd7838..5f043cdd996 100644 --- a/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/npm_packages_shared_examples.rb @@ -876,3 +876,67 @@ RSpec.shared_examples 'rejects invalid package names' do expect(Gitlab::Json.parse(response.body)).to eq({ 'error' => 'package_name should be a valid file path' }) end end + +RSpec.shared_examples 'handling get metadata requests for packages in multiple projects' do + let_it_be(:project2) { create(:project, namespace: namespace) } + let_it_be(:package2) do + create(:npm_package, + project: project2, + name: "@#{group.path}/scoped_package", + version: '1.2.0') + end + + let(:headers) { build_token_auth_header(personal_access_token.token) } + + subject { get(url, headers: headers) } + + before_all do + project.update!(visibility: 'private') + + group.add_guest(user) + project.add_reporter(user) + project2.add_reporter(user) + end + + it 'includes all matching package versions in the response' do + subject + + expect(json_response['versions'].keys).to match_array([package.version, package2.version]) + end + + context 'with the feature flag disabled' do + before do + stub_feature_flags(npm_allow_packages_in_multiple_projects: false) + end + + it 'returns matching package versions from only one project' do + subject + + expect(json_response['versions'].keys).to match_array([package2.version]) + end + end + + context 'with limited access to the project with the last package version' do + before_all do + project2.add_guest(user) + end + + it 'includes matching package versions from authorized projects in the response' do + subject + + expect(json_response['versions'].keys).to contain_exactly(package.version) + end + end + + context 'with limited access to the project with the first package version' do + before do + project.add_guest(user) + end + + it 'includes matching package versions from authorized projects in the response' do + subject + + expect(json_response['versions'].keys).to contain_exactly(package2.version) + end + end +end diff --git a/spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb b/spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb index 89a03d72a90..f81e8c5badf 100644 --- a/spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb +++ b/spec/views/layouts/header/_super_sidebar_logged_out.html.haml_spec.rb @@ -19,6 +19,10 @@ RSpec.describe 'layouts/header/_super_sidebar_logged_out', feature_category: :na expect(rendered).to have_content('Pricing') expect(rendered).to have_content('Contact Sales') end + + it 'renders the free trial button' do + expect(rendered).to have_content('Get free trial') + end end context 'on self-managed' do |