summaryrefslogtreecommitdiff
path: root/spec/migrations/turn_nested_groups_into_regular_groups_for_mysql_spec.rb
blob: 42109fd074396dd0e9d7f09014ea55a363c13ce1 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20170503140202_turn_nested_groups_into_regular_groups_for_mysql.rb')

describe TurnNestedGroupsIntoRegularGroupsForMysql do
  let!(:parent_group) { create(:group) }
  let!(:child_group) { create(:group, parent: parent_group) }
  let!(:project) { create(:project, :empty_repo, namespace: child_group) }
  let!(:member) { create(:user) }
  let(:migration) { described_class.new }

  before do
    parent_group.add_developer(member)

    allow(migration).to receive(:run_migration?).and_return(true)
    allow(migration).to receive(:verbose).and_return(false)
  end

  describe '#up' do
    let(:updated_project) do
      # path_with_namespace is memoized in an instance variable so we retrieve a
      # new row here to work around that.
      Project.find(project.id)
    end

    before do
      migration.up
    end

    it 'unsets the parent_id column' do
      expect(Namespace.where('parent_id IS NOT NULL').any?).to eq(false)
    end

    it 'adds members of parent groups as members to the migrated group' do
      is_member = child_group.members
        .where(user_id: member, access_level: Gitlab::Access::DEVELOPER).any?

      expect(is_member).to eq(true)
    end

    it 'update the path of the nested group' do
      child_group.reload

      expect(child_group.path).to eq("#{parent_group.name}-#{child_group.name}")
    end

    it 'renames projects of the nested group' do
      expect(updated_project.path_with_namespace)
        .to eq("#{parent_group.name}-#{child_group.name}/#{updated_project.path}")
    end

    it 'renames the repository of any projects' do
      expect(updated_project.repository.path)
        .to end_with("#{parent_group.name}-#{child_group.name}/#{updated_project.path}.git")

      expect(File.directory?(updated_project.repository.path)).to eq(true)
    end

    it 'creates a redirect route for renamed projects' do
      exists = RedirectRoute
        .where(source_type: 'Project', source_id: project.id)
        .any?

      expect(exists).to eq(true)
    end
  end
end