summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/backfill_group_features_spec.rb
blob: 4705f0d0ab94d144b51b1556b6f752a68a35a1c5 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BackgroundMigration::BackfillGroupFeatures, :migration, schema: 20220302114046 do
  let(:group_features) { table(:group_features) }
  let(:namespaces) { table(:namespaces) }

  subject { described_class.new(connection: ActiveRecord::Base.connection) }

  describe '#perform' do
    it 'creates settings for all group namespaces in range' do
      namespaces.create!(id: 1, name: 'group1', path: 'group1', type: 'Group')
      namespaces.create!(id: 2, name: 'user', path: 'user')
      namespaces.create!(id: 3, name: 'group2', path: 'group2', type: 'Group')

      # Checking that no error is raised if the group_feature for a group already exists
      namespaces.create!(id: 4, name: 'group3', path: 'group3', type: 'Group')
      group_features.create!(id: 1, group_id: 4)
      expect(group_features.count).to eq 1

      expect { subject.perform(1, 4, :namespaces, :id, 10, 0, 4) }.to change { group_features.count }.by(2)

      expect(group_features.count).to eq 3
      expect(group_features.all.pluck(:group_id)).to contain_exactly(1, 3, 4)
    end
  end
end