diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-04 03:12:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-04 03:12:36 +0300 |
commit | 4e86ca506d67f27cb4ca93b47efc53adc1c237a6 (patch) | |
tree | 8a3babe70df855216f3a9f184e3767fdd26aec57 /spec/migrations | |
parent | 16f41a5b04934bb7a7a26ac2d6516cb44b7932e3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/20211028155449_schedule_fix_merge_request_diff_commit_users_migration_spec.rb | 63 | ||||
-rw-r--r-- | spec/migrations/schedule_add_primary_email_to_emails_if_user_confirmed_spec.rb | 31 |
2 files changed, 94 insertions, 0 deletions
diff --git a/spec/migrations/20211028155449_schedule_fix_merge_request_diff_commit_users_migration_spec.rb b/spec/migrations/20211028155449_schedule_fix_merge_request_diff_commit_users_migration_spec.rb new file mode 100644 index 00000000000..6511f554436 --- /dev/null +++ b/spec/migrations/20211028155449_schedule_fix_merge_request_diff_commit_users_migration_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! 'schedule_fix_merge_request_diff_commit_users_migration' + +RSpec.describe ScheduleFixMergeRequestDiffCommitUsersMigration, :migration do + let(:migration) { described_class.new } + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') } + + describe '#up' do + it 'does nothing when there are no projects to correct' do + migration.up + + expect(Gitlab::Database::BackgroundMigrationJob.count).to be_zero + end + + it 'schedules imported projects created after July' do + project = projects.create!( + namespace_id: namespace.id, + import_type: 'gitlab_project', + created_at: '2021-08-01' + ) + + expect(migration) + .to receive(:migrate_in) + .with(2.minutes, 'FixMergeRequestDiffCommitUsers', [project.id]) + + migration.up + + expect(Gitlab::Database::BackgroundMigrationJob.count).to eq(1) + + job = Gitlab::Database::BackgroundMigrationJob.first + + expect(job.class_name).to eq('FixMergeRequestDiffCommitUsers') + expect(job.arguments).to eq([project.id]) + end + + it 'ignores projects imported before July' do + projects.create!( + namespace_id: namespace.id, + import_type: 'gitlab_project', + created_at: '2020-08-01' + ) + + migration.up + + expect(Gitlab::Database::BackgroundMigrationJob.count).to be_zero + end + + it 'ignores projects that are not imported' do + projects.create!( + namespace_id: namespace.id, + created_at: '2021-08-01' + ) + + migration.up + + expect(Gitlab::Database::BackgroundMigrationJob.count).to be_zero + end + end +end diff --git a/spec/migrations/schedule_add_primary_email_to_emails_if_user_confirmed_spec.rb b/spec/migrations/schedule_add_primary_email_to_emails_if_user_confirmed_spec.rb new file mode 100644 index 00000000000..c66ac1bd7e9 --- /dev/null +++ b/spec/migrations/schedule_add_primary_email_to_emails_if_user_confirmed_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleAddPrimaryEmailToEmailsIfUserConfirmed, :sidekiq do + let(:migration) { described_class.new } + let(:users) { table(:users) } + + let!(:user_1) { users.create!(name: 'confirmed-user-1', email: 'confirmed-1@example.com', confirmed_at: 1.day.ago, projects_limit: 100) } + let!(:user_2) { users.create!(name: 'confirmed-user-2', email: 'confirmed-2@example.com', confirmed_at: 1.day.ago, projects_limit: 100) } + let!(:user_3) { users.create!(name: 'confirmed-user-3', email: 'confirmed-3@example.com', confirmed_at: 1.day.ago, projects_limit: 100) } + let!(:user_4) { users.create!(name: 'confirmed-user-4', email: 'confirmed-4@example.com', confirmed_at: 1.day.ago, projects_limit: 100) } + + before do + stub_const("#{described_class.name}::BATCH_SIZE", 2) + stub_const("#{described_class.name}::INTERVAL", 2.minutes.to_i) + end + + it 'schedules addition of primary email to emails in delayed batches' do + Sidekiq::Testing.fake! do + freeze_time do + migration.up + + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, user_1.id, user_2.id) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, user_3.id, user_4.id) + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end +end |