Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations/20220524074947_finalize_backfill_null_note_discussion_ids_spec.rb')
-rw-r--r--spec/migrations/20220524074947_finalize_backfill_null_note_discussion_ids_spec.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/migrations/20220524074947_finalize_backfill_null_note_discussion_ids_spec.rb b/spec/migrations/20220524074947_finalize_backfill_null_note_discussion_ids_spec.rb
new file mode 100644
index 00000000000..74ad4662b3e
--- /dev/null
+++ b/spec/migrations/20220524074947_finalize_backfill_null_note_discussion_ids_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+
+RSpec.describe FinalizeBackfillNullNoteDiscussionIds, :migration do
+ subject(:migration) { described_class.new }
+
+ let(:notes) { table(:notes) }
+ let(:bg_migration_class) { Gitlab::BackgroundMigration::BackfillNoteDiscussionId }
+ let(:bg_migration) { instance_double(bg_migration_class) }
+
+ before do
+ stub_const("#{described_class.name}::BATCH_SIZE", 2)
+ end
+
+ it 'performs remaining background migrations', :aggregate_failures do
+ # Already migrated
+ notes.create!(noteable_type: 'Issue', noteable_id: 1, discussion_id: Digest::SHA1.hexdigest('note1'))
+ notes.create!(noteable_type: 'Issue', noteable_id: 1, discussion_id: Digest::SHA1.hexdigest('note2'))
+ # update required
+ record1 = notes.create!(noteable_type: 'Issue', noteable_id: 1, discussion_id: nil)
+ record2 = notes.create!(noteable_type: 'Issue', noteable_id: 1, discussion_id: nil)
+ record3 = notes.create!(noteable_type: 'Issue', noteable_id: 1, discussion_id: nil)
+
+ expect(Gitlab::BackgroundMigration).to receive(:steal).with(bg_migration_class.name.demodulize)
+ expect(bg_migration_class).to receive(:new).twice.and_return(bg_migration)
+ expect(bg_migration).to receive(:perform).with(record1.id, record2.id)
+ expect(bg_migration).to receive(:perform).with(record3.id, record3.id)
+
+ migrate!
+ end
+end