summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/backfill_namespace_traversal_ids_roots_spec.rb
blob: 96e432759725250de1b84e15984bb9eeb9dadb5a (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::BackfillNamespaceTraversalIdsRoots, :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 root namespaces' do
      described_class.new.perform(1, 3, 5)

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