diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/lib/gitlab/background_migration/backfill_note_discussion_id_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/lib/gitlab/background_migration/backfill_note_discussion_id_spec.rb')
-rw-r--r-- | spec/lib/gitlab/background_migration/backfill_note_discussion_id_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_note_discussion_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_note_discussion_id_spec.rb new file mode 100644 index 00000000000..dcb4ede36af --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_note_discussion_id_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::BackfillNoteDiscussionId do + let(:migration) { described_class.new } + let(:notes_table) { table(:notes) } + let(:existing_discussion_id) { Digest::SHA1.hexdigest('test') } + + before do + notes_table.create!(id: 1, noteable_type: 'Issue', noteable_id: 2, discussion_id: existing_discussion_id) + notes_table.create!(id: 2, noteable_type: 'Issue', noteable_id: 1, discussion_id: nil) + notes_table.create!(id: 3, noteable_type: 'MergeRequest', noteable_id: 1, discussion_id: nil) + notes_table.create!(id: 4, noteable_type: 'Commit', commit_id: RepoHelpers.sample_commit.id, discussion_id: nil) + notes_table.create!(id: 5, noteable_type: 'Issue', noteable_id: 2, discussion_id: nil) + notes_table.create!(id: 6, noteable_type: 'MergeRequest', noteable_id: 2, discussion_id: nil) + end + + it 'updates records in the specified batch', :aggregate_failures do + migration.perform(1, 5) + + expect(notes_table.where(discussion_id: nil).count).to eq(1) + + expect(notes_table.find(1).discussion_id).to eq(existing_discussion_id) + notes_table.where(id: 2..5).each do |n| + expect(n.discussion_id).to match(/\A[0-9a-f]{40}\z/) + end + end +end |