diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 15:08:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 15:08:35 +0300 |
commit | 8ef107c43390ea9c9932afb55d1318e4716fbf3b (patch) | |
tree | ad35474f833e8da50107d8ca1e348f9a953c8d7c /spec/lib | |
parent | e0df184fb182633972212cd62d6e3dc6e4bd0e62 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/background_migration/mark_duplicate_npm_packages_for_destruction_spec.rb | 78 | ||||
-rw-r--r-- | spec/lib/gitlab/gon_helper_spec.rb | 23 |
2 files changed, 97 insertions, 4 deletions
diff --git a/spec/lib/gitlab/background_migration/mark_duplicate_npm_packages_for_destruction_spec.rb b/spec/lib/gitlab/background_migration/mark_duplicate_npm_packages_for_destruction_spec.rb new file mode 100644 index 00000000000..05a19b7973c --- /dev/null +++ b/spec/lib/gitlab/background_migration/mark_duplicate_npm_packages_for_destruction_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::MarkDuplicateNpmPackagesForDestruction, schema: 20230524201454, feature_category: :package_registry do # rubocop:disable Layout/LineLength + describe '#perform' do + let(:projects_table) { table(:projects) } + let(:namespaces_table) { table(:namespaces) } + let(:packages_table) { table(:packages_packages) } + + let!(:namespace) do + namespaces_table.create!(name: 'project', path: 'project', type: 'Project') + end + + let!(:project) do + projects_table.create!( + namespace_id: namespace.id, + name: 'project', + path: 'project', + project_namespace_id: namespace.id + ) + end + + let!(:package_1) do + packages_table.create!( + project_id: project.id, + name: 'test1', + version: '1.0.0', + package_type: described_class::NPM_PACKAGE_TYPE + ) + end + + let!(:package_2) do + packages_table.create!( + project_id: project.id, + name: 'test2', + version: '1.0.0', + package_type: described_class::NPM_PACKAGE_TYPE + ) + end + + let!(:package_3) do + packages_table.create!( + project_id: project.id, + name: 'test3', + version: '1.0.0', + package_type: described_class::NPM_PACKAGE_TYPE + ) + end + + let(:migration) do + described_class.new( + start_id: projects_table.minimum(:id), + end_id: projects_table.maximum(:id), + batch_table: :packages_packages, + batch_column: :project_id, + sub_batch_size: 10, + pause_ms: 0, + connection: ApplicationRecord.connection + ) + end + + before do + # create a duplicated package without triggering model validation errors + package_2.update_column(:name, package_1.name) + package_3.update_column(:name, package_1.name) + end + + it 'marks duplicate npm packages for destruction', :aggregate_failures do + packages_marked_for_destruction = described_class::Package + .where(status: described_class::PENDING_DESTRUCTION_STATUS) + + expect { migration.perform } + .to change { packages_marked_for_destruction.count }.from(0).to(2) + expect(package_3.reload.status).not_to eq(described_class::PENDING_DESTRUCTION_STATUS) + end + end +end diff --git a/spec/lib/gitlab/gon_helper_spec.rb b/spec/lib/gitlab/gon_helper_spec.rb index 6e8997d51c3..1135cfc22ac 100644 --- a/spec/lib/gitlab/gon_helper_spec.rb +++ b/spec/lib/gitlab/gon_helper_spec.rb @@ -6,10 +6,6 @@ RSpec.describe Gitlab::GonHelper do let(:helper) do Class.new do include Gitlab::GonHelper - - def current_user - nil - end end.new end @@ -18,6 +14,7 @@ RSpec.describe Gitlab::GonHelper do let(:https) { true } before do + allow(helper).to receive(:current_user).and_return(nil) allow(helper).to receive(:gon).and_return(gon) stub_config_setting(https: https) end @@ -40,6 +37,24 @@ RSpec.describe Gitlab::GonHelper do end end + it 'sets no GitLab version' do + expect(gon).not_to receive(:version=) + + helper.add_gon_variables + end + + context 'when user is logged in' do + before do + allow(helper).to receive(:current_user).and_return(build_stubbed(:user)) + end + + it 'sets GitLab version' do + expect(gon).to receive(:version=).with(Gitlab::VERSION) + + helper.add_gon_variables + end + end + context 'when sentry is configured' do let(:clientside_dsn) { 'https://xxx@sentry.example.com/1' } let(:environment) { 'staging' } |