summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb91
1 files changed, 91 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb b/spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb
new file mode 100644
index 00000000000..45932defaf9
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb
@@ -0,0 +1,91 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::RenameTaskSystemNoteToChecklistItem do
+ let(:notes) { table(:notes) }
+ let(:projects) { table(:projects) }
+
+ let(:namespace) { table(:namespaces).create!(name: 'batchtest1', type: 'Group', path: 'space1') }
+ let(:project) { table(:projects).create!(name: 'proj1', path: 'proj1', namespace_id: namespace.id) }
+ let(:issue) { table(:issues).create!(title: 'Test issue') }
+
+ let!(:note1) do
+ notes.create!(
+ note: 'marked the task **Task 1** as complete', noteable_type: 'Issue', noteable_id: issue.id, system: true
+ )
+ end
+
+ let!(:note2) do
+ notes.create!(
+ note: 'NO_MATCH marked the task **Task 2** as complete',
+ noteable_type: 'Issue',
+ noteable_id: issue.id,
+ system: true
+ )
+ end
+
+ let!(:note3) do
+ notes.create!(
+ note: 'marked the task **Task 3** as incomplete',
+ noteable_type: 'Issue',
+ noteable_id: issue.id,
+ system: true
+ )
+ end
+
+ let!(:note4) do
+ notes.create!(
+ note: 'marked the task **Task 4** as incomplete',
+ noteable_type: 'Issue',
+ noteable_id: issue.id,
+ system: true
+ )
+ end
+
+ let!(:metadata1) { table(:system_note_metadata).create!(note_id: note1.id, action: :task) }
+ let!(:metadata2) { table(:system_note_metadata).create!(note_id: note2.id, action: :task) }
+ let!(:metadata3) { table(:system_note_metadata).create!(note_id: note3.id, action: :task) }
+ let!(:metadata4) { table(:system_note_metadata).create!(note_id: note4.id, action: :not_task) }
+
+ let(:migration) do
+ described_class.new(
+ start_id: metadata1.id,
+ end_id: metadata4.id,
+ batch_table: :system_note_metadata,
+ batch_column: :id,
+ sub_batch_size: 2,
+ pause_ms: 2,
+ connection: ApplicationRecord.connection
+ )
+ end
+
+ subject(:perform_migration) { migration.perform }
+
+ it 'renames task to checklist item in task system notes that match', :aggregate_failures do
+ expect do
+ perform_migration
+
+ note1.reload
+ note2.reload
+ note3.reload
+ note4.reload
+ end.to change(note1, :note).to('marked the checklist item **Task 1** as complete').and(
+ not_change(note2, :note).from('NO_MATCH marked the task **Task 2** as complete')
+ ).and(
+ change(note3, :note).to('marked the checklist item **Task 3** as incomplete')
+ ).and(
+ not_change(note4, :note).from('marked the task **Task 4** as incomplete')
+ )
+ end
+
+ it 'updates in batches' do
+ expect { perform_migration }.to make_queries_matching(/UPDATE notes/, 2)
+ end
+
+ it 'tracks timings of queries' do
+ expect(migration.batch_metrics.timings).to be_empty
+
+ expect { perform_migration }.to change { migration.batch_metrics.timings }
+ end
+end