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

20220420135946_update_batched_background_migration_arguments_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6dbee483e1586a61c9d988ebb9147922f18933b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require 'spec_helper'

require_migration!

RSpec.describe UpdateBatchedBackgroundMigrationArguments do
  let(:batched_migrations) { table(:batched_background_migrations) }

  before do
    common_attributes = {
      max_value: 10,
      batch_size: 5,
      sub_batch_size: 2,
      interval: 2.minutes,
      table_name: 'events',
      column_name: 'id'
    }

    batched_migrations.create!(common_attributes.merge(job_class_name: 'Job1', job_arguments: '[]'))
    batched_migrations.create!(common_attributes.merge(job_class_name: 'Job2', job_arguments: '["some_argument"]'))
    batched_migrations.create!(common_attributes.merge(job_class_name: 'Job3', job_arguments: '[]'))
  end

  describe '#up' do
    it 'updates batched migration arguments to have an empty jsonb array' do
      expect { migrate! }
        .to change { batched_migrations.where("job_arguments = '[]'").count }.from(0).to(2)
        .and change { batched_migrations.where("job_arguments = '\"[]\"'").count }.from(2).to(0)
    end
  end

  describe '#down' do
    before do
      migrate!
    end

    it 'reverts batched migration arguments to have the previous default' do
      expect { schema_migrate_down! }
        .to change { batched_migrations.where("job_arguments = '\"[]\"'").count }.from(0).to(2)
        .and change { batched_migrations.where("job_arguments = '[]'").count }.from(2).to(0)
    end
  end
end