diff options
author | Heinrich Lee Yu <heinrich@gitlab.com> | 2019-02-28 14:15:30 +0300 |
---|---|---|
committer | Heinrich Lee Yu <heinrich@gitlab.com> | 2019-04-06 03:29:51 +0300 |
commit | a8a4518099cceec5826bb9ea5d9e3198c5a10698 (patch) | |
tree | 16a2767d7bf1d6ee05f771586e82d6efbe75971d /spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb | |
parent | 8e33e7cf474b61bbc684d993d86cb5aa775a01d0 (diff) |
Clean up `noteable_id` for notes on commits
This was incorrectly set by a bug in:
https://gitlab.com/gitlab-org/gitlab-ce/issues/54924
Also adds a `batch_size` option to `update_column_in_batches`
Diffstat (limited to 'spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb')
-rw-r--r-- | spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb b/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb new file mode 100644 index 00000000000..572b7dfd0c8 --- /dev/null +++ b/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190313092516_clean_up_noteable_id_for_notes_on_commits.rb') + +describe CleanUpNoteableIdForNotesOnCommits, :migration do + let(:notes) { table(:notes) } + + before do + notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test') + notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test') + notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test') + + notes.create!(noteable_type: 'Issue', noteable_id: 1, note: 'Test') + notes.create!(noteable_type: 'MergeRequest', noteable_id: 1, note: 'Test') + notes.create!(noteable_type: 'Snippet', noteable_id: 1, note: 'Test') + end + + it 'clears noteable_id for notes on commits' do + expect { migrate! }.to change { dirty_notes_on_commits.count }.from(3).to(0) + end + + it 'does not clear noteable_id for other notes' do + expect { migrate! }.not_to change { other_notes.count } + end + + def dirty_notes_on_commits + notes.where(noteable_type: 'Commit').where('noteable_id IS NOT NULL') + end + + def other_notes + notes.where("noteable_type != 'Commit' AND noteable_id IS NOT NULL") + end +end |