2017-05-03 16:08:27 +00:00
|
|
|
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
|
2017-06-21 13:48:12 +00:00
|
|
|
is_member = child_group.members
|
|
|
|
.where(user_id: member, access_level: Gitlab::Access::DEVELOPER).any?
|
2017-05-03 16:08:27 +00:00
|
|
|
|
|
|
|
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
|
2017-07-20 09:34:09 +00:00
|
|
|
expect(updated_project.full_path)
|
2017-06-21 13:48:12 +00:00
|
|
|
.to eq("#{parent_group.name}-#{child_group.name}/#{updated_project.path}")
|
2017-05-03 16:08:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renames the repository of any projects' do
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(updated_project.repository.path)
|
|
|
|
.to end_with("#{parent_group.name}-#{child_group.name}/#{updated_project.path}.git")
|
2017-05-03 16:08:27 +00:00
|
|
|
|
|
|
|
expect(File.directory?(updated_project.repository.path)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a redirect route for renamed projects' do
|
2017-06-21 13:48:12 +00:00
|
|
|
exists = RedirectRoute
|
|
|
|
.where(source_type: 'Project', source_id: project.id)
|
|
|
|
.any?
|
2017-05-03 16:08:27 +00:00
|
|
|
|
|
|
|
expect(exists).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|