2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::BackgroundMigration::BackfillPushRulesIdInProjects, :migration, schema: 2020_03_25_162730 do
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:push_rules) { table(:push_rules) }
|
|
|
|
let(:projects) { table(:projects) }
|
|
|
|
let(:project_settings) { table(:project_settings) }
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
it 'creates new project push_rules for all push rules in the range' do
|
2021-02-22 17:27:13 +05:30
|
|
|
project_1 = projects.create!(id: 1, namespace_id: namespace.id)
|
|
|
|
project_2 = projects.create!(id: 2, namespace_id: namespace.id)
|
|
|
|
project_3 = projects.create!(id: 3, namespace_id: namespace.id)
|
|
|
|
project_settings_1 = project_settings.create!(project_id: project_1.id)
|
|
|
|
project_settings_2 = project_settings.create!(project_id: project_2.id)
|
|
|
|
project_settings_3 = project_settings.create!(project_id: project_3.id)
|
|
|
|
push_rule_1 = push_rules.create!(id: 5, is_sample: false, project_id: project_1.id)
|
|
|
|
push_rule_2 = push_rules.create!(id: 6, is_sample: false, project_id: project_2.id)
|
|
|
|
push_rules.create!(id: 8, is_sample: false, project_id: 3)
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
subject.perform(5, 7)
|
|
|
|
|
|
|
|
expect(project_settings_1.reload.push_rule_id).to eq(push_rule_1.id)
|
|
|
|
expect(project_settings_2.reload.push_rule_id).to eq(push_rule_2.id)
|
|
|
|
expect(project_settings_3.reload.push_rule_id).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|