diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-04 18:08:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-04 18:08:48 +0000 |
commit | 9c66c38ab6ce56cfe06eca21f717977f1684f08c (patch) | |
tree | 84fc6c7ebd49b8b6f73371b30b641d582fdb9725 /spec | |
parent | 333d6f857ee7d329d4c53c874e6858679306442f (diff) | |
download | gitlab-ce-9c66c38ab6ce56cfe06eca21f717977f1684f08c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js | 57 | ||||
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/auth/o_auth/user_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/unnested_in_filters/rewriter_spec.rb | 26 | ||||
-rw-r--r-- | spec/models/deployment_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/namespace_setting_spec.rb | 76 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/user_detail_spec.rb | 85 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 112 |
9 files changed, 216 insertions, 189 deletions
diff --git a/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js b/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js index f0fa9592419..20a459e2c1a 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js @@ -1,7 +1,7 @@ -import { GlKeysetPagination } from '@gitlab/ui'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import PackageVersionsList from '~/packages_and_registries/package_registry/components/details/package_versions_list.vue'; import PackagesListLoader from '~/packages_and_registries/shared/components/packages_list_loader.vue'; +import RegistryList from '~/packages_and_registries/shared/components/registry_list.vue'; import VersionRow from '~/packages_and_registries/package_registry/components/details/version_row.vue'; import { packageData } from '../../mock_data'; @@ -21,7 +21,7 @@ describe('PackageVersionsList', () => { const uiElements = { findLoader: () => wrapper.findComponent(PackagesListLoader), - findListPagination: () => wrapper.findComponent(GlKeysetPagination), + findRegistryList: () => wrapper.findComponent(RegistryList), findEmptySlot: () => wrapper.findComponent(EmptySlotStub), findListRow: () => wrapper.findAllComponents(VersionRow), }; @@ -33,6 +33,9 @@ describe('PackageVersionsList', () => { isLoading: false, ...props, }, + stubs: { + RegistryList, + }, slots: { 'empty-state': EmptySlotStub, }, @@ -55,8 +58,8 @@ describe('PackageVersionsList', () => { expect(uiElements.findEmptySlot().exists()).toBe(false); }); - it('does not display pagination', () => { - expect(uiElements.findListPagination().exists()).toBe(false); + it('does not display registry list', () => { + expect(uiElements.findRegistryList().exists()).toBe(false); }); }); @@ -77,8 +80,8 @@ describe('PackageVersionsList', () => { expect(uiElements.findListRow().exists()).toBe(false); }); - it('does not display pagination', () => { - expect(uiElements.findListPagination().exists()).toBe(false); + it('does not display registry list', () => { + expect(uiElements.findRegistryList().exists()).toBe(false); }); }); @@ -87,6 +90,19 @@ describe('PackageVersionsList', () => { mountComponent(); }); + it('displays package registry list', () => { + expect(uiElements.findRegistryList().exists()).toEqual(true); + }); + + it('binds the right props', () => { + expect(uiElements.findRegistryList().props()).toMatchObject({ + items: packageList, + pagination: {}, + isLoading: false, + hiddenDelete: true, + }); + }); + it('displays package version rows', () => { expect(uiElements.findListRow().exists()).toEqual(true); expect(uiElements.findListRow()).toHaveLength(packageList.length); @@ -102,27 +118,6 @@ describe('PackageVersionsList', () => { }); }); - describe('pagination display', () => { - it('does not display pagination if there is no previous or next page', () => { - expect(uiElements.findListPagination().exists()).toBe(false); - }); - - it('displays pagination if pageInfo.hasNextPage is true', async () => { - await wrapper.setProps({ pageInfo: { hasNextPage: true } }); - expect(uiElements.findListPagination().exists()).toBe(true); - }); - - it('displays pagination if pageInfo.hasPreviousPage is true', async () => { - await wrapper.setProps({ pageInfo: { hasPreviousPage: true } }); - expect(uiElements.findListPagination().exists()).toBe(true); - }); - - it('displays pagination if both pageInfo.hasNextPage and pageInfo.hasPreviousPage are true', async () => { - await wrapper.setProps({ pageInfo: { hasNextPage: true, hasPreviousPage: true } }); - expect(uiElements.findListPagination().exists()).toBe(true); - }); - }); - it('does not display loader', () => { expect(uiElements.findLoader().exists()).toBe(false); }); @@ -137,14 +132,14 @@ describe('PackageVersionsList', () => { mountComponent({ pageInfo: { hasNextPage: true } }); }); - it('emits prev-page event when paginator emits prev event', () => { - uiElements.findListPagination().vm.$emit('prev'); + it('emits prev-page event when registry list emits prev event', () => { + uiElements.findRegistryList().vm.$emit('prev-page'); expect(wrapper.emitted('prev-page')).toHaveLength(1); }); - it('emits next-page when paginator emits next event', () => { - uiElements.findListPagination().vm.$emit('next'); + it('emits next-page when registry list emits next event', () => { + uiElements.findRegistryList().vm.$emit('next-page'); expect(wrapper.emitted('next-page')).toHaveLength(1); }); diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index a108b8bffbf..cbab6072ff6 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -604,16 +604,6 @@ RSpec.describe ApplicationHelper do it 'returns nil' do expect(helper.dispensable_render).to be_nil end - - context 'when the feature flag is disabled' do - before do - stub_feature_flags(dispensable_render: false) - end - - it 'raises an error' do - expect { helper.dispensable_render }.to raise_error(StandardError) - end - end end end @@ -658,16 +648,6 @@ RSpec.describe ApplicationHelper do it 'returns nil' do expect(helper.dispensable_render_if_exists).to be_nil end - - context 'when the feature flag is disabled' do - before do - stub_feature_flags(dispensable_render: false) - end - - it 'raises an error' do - expect { helper.dispensable_render_if_exists }.to raise_error(StandardError) - end - end end end diff --git a/spec/lib/gitlab/auth/o_auth/user_spec.rb b/spec/lib/gitlab/auth/o_auth/user_spec.rb index bb81621ec92..0d835b16f0a 100644 --- a/spec/lib/gitlab/auth/o_auth/user_spec.rb +++ b/spec/lib/gitlab/auth/o_auth/user_spec.rb @@ -935,7 +935,7 @@ RSpec.describe Gitlab::Auth::OAuth::User do end it "does not update the user location" do - expect(gl_user.location).to be_nil + expect(gl_user.location).to be_blank expect(gl_user.user_synced_attributes_metadata.location_synced).to be(false) end end diff --git a/spec/lib/unnested_in_filters/rewriter_spec.rb b/spec/lib/unnested_in_filters/rewriter_spec.rb index fe34fba579b..bba27276037 100644 --- a/spec/lib/unnested_in_filters/rewriter_spec.rb +++ b/spec/lib/unnested_in_filters/rewriter_spec.rb @@ -69,15 +69,21 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:recorded_queries) { ActiveRecord::QueryRecorder.new { rewriter.rewrite.load } } let(:relation) { User.where(state: :active, user_type: %i(support_bot alert_bot)).limit(2) } + let(:users_default_select_fields) do + User.default_select_columns + .map { |field| "\"users\".\"#{field.name}\"" } + .join(',') + end + let(:expected_query) do <<~SQL SELECT - "users".* + #{users_default_select_fields} FROM unnest('{1,2}'::smallint[]) AS "user_types"("user_type"), LATERAL ( SELECT - "users".* + #{users_default_select_fields} FROM "users" WHERE @@ -101,13 +107,13 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL SELECT - "users".* + #{users_default_select_fields} FROM unnest(ARRAY(SELECT "users"."state" FROM "users")::character varying[]) AS "states"("state"), unnest('{1,2}'::smallint[]) AS "user_types"("user_type"), LATERAL ( SELECT - "users".* + #{users_default_select_fields} FROM "users" WHERE @@ -129,12 +135,12 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL SELECT - "users".* + #{users_default_select_fields} FROM unnest('{active,blocked,banned}'::charactervarying[]) AS "states"("state"), LATERAL ( SELECT - "users".* + #{users_default_select_fields} FROM "users" WHERE @@ -181,8 +187,6 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL - SELECT - "users".* FROM "users" WHERE @@ -217,7 +221,7 @@ RSpec.describe UnnestedInFilters::Rewriter do end it 'changes the query' do - expect(issued_query.gsub(/\s/, '')).to start_with(expected_query.gsub(/\s/, '')) + expect(issued_query.gsub(/\s/, '')).to include(expected_query.gsub(/\s/, '')) end end @@ -226,8 +230,6 @@ RSpec.describe UnnestedInFilters::Rewriter do let(:expected_query) do <<~SQL - SELECT - "users".* FROM "users" WHERE @@ -257,7 +259,7 @@ RSpec.describe UnnestedInFilters::Rewriter do end it 'does not rewrite the in statement for the joined table' do - expect(issued_query.gsub(/\s/, '')).to start_with(expected_query.gsub(/\s/, '')) + expect(issued_query.gsub(/\s/, '')).to include(expected_query.gsub(/\s/, '')) end end diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index fb3883820fd..6ef6dcf0e7b 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -170,18 +170,7 @@ RSpec.describe Deployment do end end - it 'executes Deployments::DropOlderDeploymentsWorker asynchronously' do - stub_feature_flags(prevent_outdated_deployment_jobs: false) - - expect(Deployments::DropOlderDeploymentsWorker) - .to receive(:perform_async).once.with(deployment.id) - - deployment.run! - end - - it 'does not execute Deployments::DropOlderDeploymentsWorker when FF enabled' do - stub_feature_flags(prevent_outdated_deployment_jobs: true) - + it 'does not execute Deployments::DropOlderDeploymentsWorker' do expect(Deployments::DropOlderDeploymentsWorker) .not_to receive(:perform_async).with(deployment.id) diff --git a/spec/models/namespace_setting_spec.rb b/spec/models/namespace_setting_spec.rb index e06a6a30f9a..0bf6fdf4fa0 100644 --- a/spec/models/namespace_setting_spec.rb +++ b/spec/models/namespace_setting_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe NamespaceSetting, type: :model do +RSpec.describe NamespaceSetting, feature_category: :subgroups, type: :model do it_behaves_like 'sanitizable', :namespace_settings, %i[default_branch_name] # Relationships @@ -235,6 +235,80 @@ RSpec.describe NamespaceSetting, type: :model do end end + describe '#allow_runner_registration_token?' do + subject(:group_setting) { group.allow_runner_registration_token? } + + context 'when a top-level group' do + let_it_be(:settings) { create(:namespace_settings) } + let_it_be(:group) { create(:group, namespace_settings: settings) } + + before do + group.update!(allow_runner_registration_token: allow_runner_registration_token) + end + + context 'when :allow_runner_registration_token is false' do + let(:allow_runner_registration_token) { false } + + it 'returns false', :aggregate_failures do + is_expected.to be_falsey + + expect(settings.allow_runner_registration_token).to be_falsey + end + + it 'does not query the db' do + expect { group_setting }.not_to exceed_query_limit(0) + end + end + + context 'when :allow_runner_registration_token is true' do + let(:allow_runner_registration_token) { true } + + it 'returns true', :aggregate_failures do + is_expected.to be_truthy + + expect(settings.allow_runner_registration_token).to be_truthy + end + + context 'when disallowed by application setting' do + before do + stub_application_setting(allow_runner_registration_token: false) + end + + it { is_expected.to be_falsey } + end + end + end + + context 'when a group has parent groups' do + let_it_be_with_refind(:parent) { create(:group) } + let_it_be_with_refind(:group) { create(:group, parent: parent) } + + before do + parent.update!(allow_runner_registration_token: allow_runner_registration_token) + end + + context 'when a parent group has runner registration disabled' do + let(:allow_runner_registration_token) { false } + + it { is_expected.to be_falsey } + end + + context 'when all parent groups have runner registration enabled' do + let(:allow_runner_registration_token) { true } + + it { is_expected.to be_truthy } + + context 'when disallowed by application setting' do + before do + stub_application_setting(allow_runner_registration_token: false) + end + + it { is_expected.to be_falsey } + end + end + end + end + describe '#delayed_project_removal' do it_behaves_like 'a cascading namespace setting boolean attribute', settings_attribute_name: :delayed_project_removal end diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 706b73cb607..bdf49227aaa 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -363,6 +363,10 @@ RSpec.describe Namespace do it { is_expected.to delegate_method(:name).to(:owner).with_prefix.allow_nil } it { is_expected.to delegate_method(:avatar_url).to(:owner).allow_nil } it { is_expected.to delegate_method(:prevent_sharing_groups_outside_hierarchy).to(:namespace_settings).allow_nil } + it { is_expected.to delegate_method(:runner_registration_enabled).to(:namespace_settings) } + it { is_expected.to delegate_method(:runner_registration_enabled?).to(:namespace_settings) } + it { is_expected.to delegate_method(:allow_runner_registration_token).to(:namespace_settings) } + it { is_expected.to delegate_method(:allow_runner_registration_token?).to(:namespace_settings) } it { is_expected.to delegate_method(:maven_package_requests_forwarding).to(:package_settings) } it { is_expected.to delegate_method(:pypi_package_requests_forwarding).to(:package_settings) } it { is_expected.to delegate_method(:npm_package_requests_forwarding).to(:package_settings) } @@ -371,6 +375,16 @@ RSpec.describe Namespace do is_expected.to delegate_method(:prevent_sharing_groups_outside_hierarchy=).to(:namespace_settings) .with_arguments(:args).allow_nil end + + it do + is_expected.to delegate_method(:runner_registration_enabled=).to(:namespace_settings) + .with_arguments(:args) + end + + it do + is_expected.to delegate_method(:allow_runner_registration_token=).to(:namespace_settings) + .with_arguments(:args) + end end describe "Respond to" do diff --git a/spec/models/user_detail_spec.rb b/spec/models/user_detail_spec.rb index ed55aca49b7..1893b6530a5 100644 --- a/spec/models/user_detail_spec.rb +++ b/spec/models/user_detail_spec.rb @@ -68,26 +68,34 @@ RSpec.describe UserDetail do end end - describe '.user_fields_changed?' do - let(:user) { create(:user) } - - context 'when user detail fields unchanged' do - it 'returns false' do - expect(described_class.user_fields_changed?(user)).to be false - end - - %i[linkedin location organization skype twitter website_url].each do |attr| - context "when #{attr} is changed" do - before do - user[attr] = 'new value' - end - - it 'returns true' do - expect(described_class.user_fields_changed?(user)).to be true - end - end + describe '#save' do + let(:user_detail) do + create(:user_detail, + bio: 'bio', + linkedin: 'linkedin', + twitter: 'twitter', + skype: 'skype', + location: 'location', + organization: 'organization', + website_url: 'https://example.com') + end + + shared_examples 'prevents `nil` value' do |attr| + it 'converts `nil` to the empty string' do + user_detail[attr] = nil + expect { user_detail.save! } + .to change { user_detail[attr] }.to('') + .and not_change { user_detail.attributes.except(attr.to_s) } end end + + it_behaves_like 'prevents `nil` value', :bio + it_behaves_like 'prevents `nil` value', :linkedin + it_behaves_like 'prevents `nil` value', :twitter + it_behaves_like 'prevents `nil` value', :skype + it_behaves_like 'prevents `nil` value', :location + it_behaves_like 'prevents `nil` value', :organization + it_behaves_like 'prevents `nil` value', :website_url end describe '#sanitize_attrs' do @@ -137,45 +145,4 @@ RSpec.describe UserDetail do details.save! end end - - describe '#assign_changed_fields_from_user' do - let(:user_detail) { build(:user_detail) } - - shared_examples 'syncs field with `user_details`' do |field| - it 'does not sync the field to `user_details` if unchanged' do - expect { user_detail.assign_changed_fields_from_user } - .to not_change { user_detail.public_send(field) } - end - - it 'syncs the field to `user_details` if changed' do - user_detail.user[field] = "new_value" - expect { user_detail.assign_changed_fields_from_user } - .to change { user_detail.public_send(field) } - .to("new_value") - end - - it 'truncates the field if too long' do - user_detail.user[field] = 'a' * (UserDetail::DEFAULT_FIELD_LENGTH + 1) - expect { user_detail.assign_changed_fields_from_user } - .to change { user_detail.public_send(field) } - .to('a' * UserDetail::DEFAULT_FIELD_LENGTH) - end - - it 'properly syncs nil field to `user_details' do - user_detail.user[field] = 'Test' - user_detail.user.save!(validate: false) - user_detail.user[field] = nil - expect { user_detail.assign_changed_fields_from_user } - .to change { user_detail.public_send(field) } - .to('') - end - end - - it_behaves_like 'syncs field with `user_details`', :linkedin - it_behaves_like 'syncs field with `user_details`', :location - it_behaves_like 'syncs field with `user_details`', :organization - it_behaves_like 'syncs field with `user_details`', :skype - it_behaves_like 'syncs field with `user_details`', :twitter - it_behaves_like 'syncs field with `user_details`', :website_url - end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1f116675baa..0bbf7d86b28 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -101,6 +101,24 @@ RSpec.describe User do it { is_expected.to delegate_method(:requires_credit_card_verification).to(:user_detail).allow_nil } it { is_expected.to delegate_method(:requires_credit_card_verification=).to(:user_detail).with_arguments(:args).allow_nil } + + it { is_expected.to delegate_method(:linkedin).to(:user_detail).allow_nil } + it { is_expected.to delegate_method(:linkedin=).to(:user_detail).with_arguments(:args).allow_nil } + + it { is_expected.to delegate_method(:twitter).to(:user_detail).allow_nil } + it { is_expected.to delegate_method(:twitter=).to(:user_detail).with_arguments(:args).allow_nil } + + it { is_expected.to delegate_method(:skype).to(:user_detail).allow_nil } + it { is_expected.to delegate_method(:skype=).to(:user_detail).with_arguments(:args).allow_nil } + + it { is_expected.to delegate_method(:website_url).to(:user_detail).allow_nil } + it { is_expected.to delegate_method(:website_url=).to(:user_detail).with_arguments(:args).allow_nil } + + it { is_expected.to delegate_method(:location).to(:user_detail).allow_nil } + it { is_expected.to delegate_method(:location=).to(:user_detail).with_arguments(:args).allow_nil } + + it { is_expected.to delegate_method(:organization).to(:user_detail).allow_nil } + it { is_expected.to delegate_method(:organization=).to(:user_detail).with_arguments(:args).allow_nil } end describe 'associations' do @@ -173,17 +191,51 @@ RSpec.describe User do expect(create(:user).user_detail).not_to be_persisted end - it 'creates `user_detail` when `bio` is given' do - user = create(:user, bio: 'my bio') + shared_examples 'delegated field' do |field| + it 'creates `user_detail` when the field is given' do + user = create(:user, field => 'my field') + + expect(user.user_detail).to be_persisted + expect(user.user_detail[field]).to eq('my field') + end + + it 'delegates to `user_detail`' do + user = create(:user, field => 'my field') + + expect(user.public_send(field)).to eq(user.user_detail[field]) + end + + it 'creates `user_detail` when first updated' do + user = create(:user) + + expect { user.update!(field => 'my field') }.to change { user.user_detail.persisted? }.from(false).to(true) + end + end + + it_behaves_like 'delegated field', :bio + it_behaves_like 'delegated field', :linkedin + it_behaves_like 'delegated field', :twitter + it_behaves_like 'delegated field', :skype + it_behaves_like 'delegated field', :location + it_behaves_like 'delegated field', :organization + + it 'creates `user_detail` when `website_url` is given' do + user = create(:user, website_url: 'https://example.com') expect(user.user_detail).to be_persisted - expect(user.user_detail.bio).to eq('my bio') + expect(user.user_detail.website_url).to eq('https://example.com') end - it 'delegates `bio` to `user_detail`' do - user = create(:user, bio: 'my bio') + it 'delegates `website_url` to `user_detail`' do + user = create(:user, website_url: 'http://example.com') - expect(user.bio).to eq(user.user_detail.bio) + expect(user.website_url).to eq(user.user_detail.website_url) + end + + it 'creates `user_detail` when `website_url` is first updated' do + user = create(:user) + + expect { user.update!(website_url: 'https://example.com') }.to change { user.user_detail.persisted? }.from(false).to(true) end it 'delegates `pronouns` to `user_detail`' do @@ -197,12 +249,6 @@ RSpec.describe User do expect(user.pronunciation).to eq(user.user_detail.pronunciation) end - - it 'creates `user_detail` when `bio` is first updated' do - user = create(:user) - - expect { user.update!(bio: 'my bio') }.to change { user.user_detail.persisted? }.from(false).to(true) - end end describe '#abuse_report' do @@ -3648,19 +3694,14 @@ RSpec.describe User do describe '#sanitize_attrs' do let(:user) { build(:user, name: 'test <& user', skype: 'test&user') } - it 'encodes HTML entities in the Skype attribute' do - expect { user.sanitize_attrs }.to change { user.skype }.to('test&user') - end - it 'does not encode HTML entities in the name attribute' do expect { user.sanitize_attrs }.not_to change { user.name } end it 'sanitizes attr from html tags' do - user = create(:user, name: '<a href="//example.com">Test<a>', twitter: '<a href="//evil.com">https://twitter.com<a>') + user = create(:user, name: '<a href="//example.com">Test<a>') expect(user.name).to eq('Test') - expect(user.twitter).to eq('https://twitter.com') end it 'sanitizes attr from js scripts' do @@ -5482,41 +5523,6 @@ RSpec.describe User do end end - describe '#ensure_user_detail_assigned' do - let(:user) { build(:user) } - - context 'when no user detail field has been changed' do - before do - allow(UserDetail) - .to receive(:user_fields_changed?) - .and_return(false) - end - - it 'does not assign user details before save' do - expect(user.user_detail) - .not_to receive(:assign_changed_fields_from_user) - - user.save! - end - end - - context 'when a user detail field has been changed' do - before do - allow(UserDetail) - .to receive(:user_fields_changed?) - .and_return(true) - end - - it 'assigns user details before save' do - expect(user.user_detail) - .to receive(:assign_changed_fields_from_user) - .and_call_original - - user.save! - end - end - end - describe '#username_changed_hook' do context 'for a new user' do let(:user) { build(:user) } |