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

schedule_set_confidential_note_events_on_services_spec.rb « active_record « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4395e2f82641a377cb1f335d87f7684a42e27249 (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
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20180122154930_schedule_set_confidential_note_events_on_services.rb')

describe ScheduleSetConfidentialNoteEventsOnServices, :migration, :sidekiq do
  let(:services_table) { table(:services) }
  let(:migration_class) { Gitlab::BackgroundMigration::SetConfidentialNoteEventsOnServices }
  let(:migration_name)  { migration_class.to_s.demodulize }

  let!(:service_1)        { services_table.create!(confidential_note_events: nil, note_events: true) }
  let!(:service_2)        { services_table.create!(confidential_note_events: nil, note_events: true) }
  let!(:service_migrated) { services_table.create!(confidential_note_events: true, note_events: true) }
  let!(:service_skip)     { services_table.create!(confidential_note_events: nil, note_events: false) }
  let!(:service_new)      { services_table.create!(confidential_note_events: false, note_events: true) }
  let!(:service_4)        { services_table.create!(confidential_note_events: nil, note_events: true) }

  before do
    stub_const("#{described_class}::BATCH_SIZE", 1)
  end

  it 'schedules background migrations at correct time' do
    Sidekiq::Testing.fake! do
      Timecop.freeze do
        migrate!

        expect(migration_name).to be_scheduled_delayed_migration(20.minutes, service_1.id, service_1.id)
        expect(migration_name).to be_scheduled_delayed_migration(40.minutes, service_2.id, service_2.id)
        expect(migration_name).to be_scheduled_delayed_migration(60.minutes, service_4.id, service_4.id)
        expect(BackgroundMigrationWorker.jobs.size).to eq 3
      end
    end
  end

  it 'correctly processes services' do
    Sidekiq::Testing.inline! do
      expect(services_table.where(confidential_note_events: nil).count).to eq 4
      expect(services_table.where(confidential_note_events: true).count).to eq 1

      migrate!

      expect(services_table.where(confidential_note_events: nil).count).to eq 1
      expect(services_table.where(confidential_note_events: true).count).to eq 4
    end
  end
end