summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/backfill_namespace_traversal_ids_children_spec.rb
blob: 35928deff82dfa3633d924beb809d215c8df6aa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BackgroundMigration::BackfillNamespaceTraversalIdsChildren, :migration, schema: 20210506065000 do
  let(:namespaces_table) { table(:namespaces) }

  let!(:user_namespace) { namespaces_table.create!(id: 1, name: 'user', path: 'user', type: nil) }
  let!(:root_group) { namespaces_table.create!(id: 2, name: 'group', path: 'group', type: 'Group', parent_id: nil) }
  let!(:sub_group) { namespaces_table.create!(id: 3, name: 'subgroup', path: 'subgroup', type: 'Group', parent_id: 2) }

  describe '#perform' do
    it 'backfills traversal_ids for child namespaces' do
      described_class.new.perform(1, 3, 5)

      expect(user_namespace.reload.traversal_ids).to eq([])
      expect(root_group.reload.traversal_ids).to eq([])
      expect(sub_group.reload.traversal_ids).to eq([root_group.id, sub_group.id])
    end
  end
end