turn_nested_groups_into_regular_groups_for_mysql_spec.rb 2.32 KB
Newer Older
1 2 3 4
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20170503140202_turn_nested_groups_into_regular_groups_for_mysql.rb')

describe TurnNestedGroupsIntoRegularGroupsForMysql do
5 6 7 8
  let!(:parent_group) { create(:group) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
  let!(:child_group) { create(:group, parent: parent_group) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
  let!(:project) { create(:project, :legacy_storage, :empty_repo, namespace: child_group) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
  let!(:member) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
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
  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
34 35
      is_member = child_group.members
        .where(user_id: member, access_level: Gitlab::Access::DEVELOPER).any?
36 37 38 39 40 41 42 43 44 45 46

      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
47
      expect(updated_project.full_path)
48
        .to eq("#{parent_group.name}-#{child_group.name}/#{updated_project.path}")
49 50 51
    end

    it 'renames the repository of any projects' do
52 53 54 55 56
      repo_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
        updated_project.repository.path
      end

      expect(repo_path)
57
        .to end_with("#{parent_group.name}-#{child_group.name}/#{updated_project.path}.git")
58

59
      expect(File.directory?(repo_path)).to eq(true)
60 61 62
    end

    it 'creates a redirect route for renamed projects' do
63 64 65
      exists = RedirectRoute
        .where(source_type: 'Project', source_id: project.id)
        .any?
66 67 68 69 70

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