diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-29 12:08:30 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-29 12:08:30 +0000 |
commit | afbe8fe679be2c9680e6b2bf262b8cf48311b691 (patch) | |
tree | 1ff7f1996f6514d1042d0dd207f9bc5a71deba51 /spec | |
parent | 99000aec9240ac4bcfa0babd54acea8cee3570de (diff) | |
download | gitlab-ce-afbe8fe679be2c9680e6b2bf262b8cf48311b691.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
3 files changed, 0 insertions, 128 deletions
diff --git a/spec/lib/gitlab/background_migration/add_primary_email_to_emails_if_user_confirmed_spec.rb b/spec/lib/gitlab/background_migration/add_primary_email_to_emails_if_user_confirmed_spec.rb deleted file mode 100644 index b50a55a9e41..00000000000 --- a/spec/lib/gitlab/background_migration/add_primary_email_to_emails_if_user_confirmed_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::BackgroundMigration::AddPrimaryEmailToEmailsIfUserConfirmed do - let(:users) { table(:users) } - let(:emails) { table(:emails) } - - let!(:unconfirmed_user) { users.create!(name: 'unconfirmed', email: 'unconfirmed@example.com', confirmed_at: nil, projects_limit: 100) } - let!(:confirmed_user_1) { users.create!(name: 'confirmed-1', email: 'confirmed-1@example.com', confirmed_at: 1.day.ago, projects_limit: 100) } - let!(:confirmed_user_2) { users.create!(name: 'confirmed-2', email: 'confirmed-2@example.com', confirmed_at: 1.day.ago, projects_limit: 100) } - let!(:email) { emails.create!(user_id: confirmed_user_1.id, email: 'confirmed-1@example.com', confirmed_at: 1.day.ago) } - - let(:perform) { described_class.new.perform(users.first.id, users.last.id) } - - it 'adds the primary email of confirmed users to Emails, unless already added', :aggregate_failures do - expect(emails.where(email: [unconfirmed_user.email, confirmed_user_2.email])).to be_empty - - expect { perform }.not_to raise_error - - expect(emails.where(email: unconfirmed_user.email).count).to eq(0) - expect(emails.where(email: confirmed_user_1.email, user_id: confirmed_user_1.id).count).to eq(1) - expect(emails.where(email: confirmed_user_2.email, user_id: confirmed_user_2.id).count).to eq(1) - - email_2 = emails.find_by(email: confirmed_user_2.email, user_id: confirmed_user_2.id) - expect(email_2.confirmed_at).to eq(confirmed_user_2.reload.confirmed_at) - end - - it 'sets timestamps on the created Emails' do - perform - - email_2 = emails.find_by(email: confirmed_user_2.email, user_id: confirmed_user_2.id) - - expect(email_2.created_at).not_to be_nil - expect(email_2.updated_at).not_to be_nil - end - - context 'when a range of IDs is specified' do - let!(:confirmed_user_3) { users.create!(name: 'confirmed-3', email: 'confirmed-3@example.com', confirmed_at: 1.hour.ago, projects_limit: 100) } - let!(:confirmed_user_4) { users.create!(name: 'confirmed-4', email: 'confirmed-4@example.com', confirmed_at: 1.hour.ago, projects_limit: 100) } - - it 'only acts on the specified range of IDs', :aggregate_failures do - expect do - described_class.new.perform(confirmed_user_2.id, confirmed_user_3.id) - end.to change { Email.count }.by(2) - expect(emails.where(email: confirmed_user_4.email).count).to eq(0) - end - end -end diff --git a/spec/migrations/cleanup_after_add_primary_email_to_emails_if_user_confirmed_spec.rb b/spec/migrations/cleanup_after_add_primary_email_to_emails_if_user_confirmed_spec.rb deleted file mode 100644 index 6027199c11c..00000000000 --- a/spec/migrations/cleanup_after_add_primary_email_to_emails_if_user_confirmed_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require_migration! - -RSpec.describe CleanupAfterAddPrimaryEmailToEmailsIfUserConfirmed, :sidekiq, feature_category: :users do - let(:migration) { described_class.new } - let(:users) { table(:users) } - let(:emails) { table(:emails) } - - let!(:user_1) { users.create!(name: 'confirmed-user-1', email: 'confirmed-1@example.com', confirmed_at: 3.days.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: 'unconfirmed-user', email: 'unconfirmed@example.com', confirmed_at: nil, projects_limit: 100) } - - let!(:email_1) { emails.create!(email: 'confirmed-1@example.com', user_id: user_1.id, confirmed_at: 1.day.ago) } - let!(:email_2) { emails.create!(email: 'other_2@example.com', user_id: user_2.id, confirmed_at: 1.day.ago) } - - before do - stub_const("#{described_class.name}::BATCH_SIZE", 2) - end - - it 'consume any pending background migration job' do - expect_next_instance_of(Gitlab::BackgroundMigration::JobCoordinator) do |coordinator| - expect(coordinator).to receive(:steal).with('AddPrimaryEmailToEmailsIfUserConfirmed').twice - end - - migration.up - end - - it 'adds the primary email to emails for leftover confirmed users that do not have their primary email in the emails table', :aggregate_failures do - original_email_1_confirmed_at = email_1.reload.confirmed_at - - expect { migration.up }.to change { emails.count }.by(2) - - expect(emails.find_by(user_id: user_2.id, email: 'confirmed-2@example.com').confirmed_at).to eq(user_2.reload.confirmed_at) - expect(emails.find_by(user_id: user_3.id, email: 'confirmed-3@example.com').confirmed_at).to eq(user_3.reload.confirmed_at) - expect(email_1.reload.confirmed_at).to eq(original_email_1_confirmed_at) - - expect(emails.exists?(user_id: user_4.id)).to be(false) - end - - it 'continues in case of errors with one email' do - allow(Email).to receive(:create) { raise 'boom!' } - - expect { migration.up }.not_to raise_error - 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 deleted file mode 100644 index 98d3e9b7c7c..00000000000 --- a/spec/migrations/schedule_add_primary_email_to_emails_if_user_confirmed_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require_migration! - -RSpec.describe ScheduleAddPrimaryEmailToEmailsIfUserConfirmed, :sidekiq, feature_category: :users 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 |