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

schedule_backfill_push_rules_id_in_projects_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 37a769bbc524f083903cf4ab499ca8ff0adf8c1e (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
45
46
47
48
49
# frozen_string_literal: true

require 'spec_helper'

require Rails.root.join('db', 'post_migrate', '20200325162730_schedule_backfill_push_rules_id_in_projects.rb')

RSpec.describe ScheduleBackfillPushRulesIdInProjects do
  let(:push_rules) { table(:push_rules) }

  it 'adds global rule association to application settings' do
    application_settings = table(:application_settings)
    setting = application_settings.create!
    sample_rule = push_rules.create!(is_sample: true)

    Sidekiq::Testing.fake! do
      disable_migrations_output { migrate! }
    end

    setting.reload
    expect(setting.push_rule_id).to eq(sample_rule.id)
  end

  it 'adds global rule association to last application settings when there is more than one record without failing' do
    application_settings = table(:application_settings)
    setting_old = application_settings.create!
    setting = application_settings.create!
    sample_rule = push_rules.create!(is_sample: true)

    Sidekiq::Testing.fake! do
      disable_migrations_output { migrate! }
    end

    expect(setting_old.reload.push_rule_id).to be_nil
    expect(setting.reload.push_rule_id).to eq(sample_rule.id)
  end

  it 'schedules worker to migrate project push rules' do
    rule_1 = push_rules.create!
    rule_2 = push_rules.create!

    Sidekiq::Testing.fake! do
      disable_migrations_output { migrate! }

      expect(BackgroundMigrationWorker.jobs.size).to eq(1)
      expect(described_class::MIGRATION)
        .to be_scheduled_delayed_migration(5.minutes, rule_1.id, rule_2.id)
    end
  end
end