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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-23 18:08:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-23 18:08:01 +0300
commitabdb550f6937ce69ec38954f24ef221d07637438 (patch)
treea8f2136768637c628f544f567fa57d63c5cf6e3b /spec/migrations
parente6d048d769240760008f0dbb6b811e1ebc675292 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/20230426085615_queue_backfill_resource_link_events_spec.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/migrations/20230426085615_queue_backfill_resource_link_events_spec.rb b/spec/migrations/20230426085615_queue_backfill_resource_link_events_spec.rb
new file mode 100644
index 00000000000..d0d948dad9d
--- /dev/null
+++ b/spec/migrations/20230426085615_queue_backfill_resource_link_events_spec.rb
@@ -0,0 +1,89 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe QueueBackfillResourceLinkEvents, feature_category: :team_planning do
+ include MigrationHelpers::WorkItemTypesHelper
+
+ let(:users) { table(:users) }
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:issues) { table(:issues) }
+ let(:notes) { table(:notes) }
+ let(:system_note_metadata) { table(:system_note_metadata) }
+
+ let(:namespace) { namespaces.create!(name: "namespace", path: "namespace") }
+ let(:project) { projects.create!(namespace_id: namespace.id, project_namespace_id: namespace.id) }
+ let(:work_item_issue_type_id) { table(:work_item_types).find_by(namespace_id: nil, name: 'Issue').id }
+ let(:issue) { issues.create!(project_id: project.id, namespace_id: project.project_namespace_id, work_item_type_id: work_item_issue_type_id) } # rubocop:disable Layout/LineLength
+ let(:user) { users.create!(name: 'user', projects_limit: 10) }
+
+ let!(:system_note_metadata_record1) do
+ note = notes.create!(noteable_type: 'Issue', noteable_id: issue.id, author_id: user.id, note: "foobar")
+
+ system_note_metadata.create!(action: 'foobar', note_id: note.id)
+ end
+
+ let!(:batched_migration) { described_class::MIGRATION }
+
+ describe '#up' do
+ %w[relate_to_parent unrelate_from_parent].each do |action_value|
+ context 'when system_note_metadata table has a row with targeted action values' do
+ let!(:system_note_metadata_record2) do
+ note = notes.create!(noteable_type: 'Issue', noteable_id: issue.id, author_id: user.id, note: "foobar")
+
+ system_note_metadata.create!(action: action_value, note_id: note.id)
+ end
+
+ let!(:system_note_metadata_record3) do
+ note = notes.create!(noteable_type: 'Issue', noteable_id: issue.id, author_id: user.id, note: "foobar")
+
+ system_note_metadata.create!(action: action_value, note_id: note.id)
+ end
+
+ it 'schedules a new batched migration with the lowest system_note_metadat record id' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(batched_migration).not_to have_scheduled_batched_migration
+ }
+
+ migration.after -> {
+ expect(batched_migration).to have_scheduled_batched_migration(
+ table_name: :system_note_metadata,
+ column_name: :id,
+ interval: described_class::DELAY_INTERVAL,
+ batch_size: described_class::BATCH_SIZE,
+ sub_batch_size: described_class::SUB_BATCH_SIZE,
+ batch_min_value: system_note_metadata_record2.id
+ )
+ }
+ end
+ end
+ end
+ end
+
+ context 'when system_note_metadata table does not ahve a row with the targeted action values' do
+ it 'does not a new batched migration' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(batched_migration).not_to have_scheduled_batched_migration
+ }
+
+ migration.after -> {
+ expect(batched_migration).not_to have_scheduled_batched_migration
+ }
+ end
+ end
+ end
+ end
+
+ describe '#down' do
+ it 'deletes all batched migration records' do
+ migrate!
+ schema_migrate_down!
+
+ expect(batched_migration).not_to have_scheduled_batched_migration
+ end
+ end
+end