2013-03-12 06:37:53 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe Projects::TransferService, services: true do
|
2014-05-28 12:04:18 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, namespace: user.namespace) }
|
2013-03-12 06:37:53 -04:00
|
|
|
|
2014-05-28 12:04:18 -04:00
|
|
|
context 'namespace -> namespace' do
|
2013-03-12 06:37:53 -04:00
|
|
|
before do
|
2015-10-06 10:09:03 -04:00
|
|
|
allow_any_instance_of(Gitlab::UploadsTransfer).
|
|
|
|
to receive(:move_project).and_return(true)
|
2014-05-28 12:04:18 -04:00
|
|
|
group.add_owner(user)
|
2015-07-02 10:47:15 -04:00
|
|
|
@result = transfer_project(project, user, group)
|
2013-03-12 06:37:53 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(@result).to be_truthy }
|
|
|
|
it { expect(project.namespace).to eq(group) }
|
2013-03-12 06:37:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'namespace -> no namespace' do
|
2014-05-28 12:04:18 -04:00
|
|
|
before do
|
2015-07-02 10:47:15 -04:00
|
|
|
@result = transfer_project(project, user, nil)
|
2014-05-28 12:04:18 -04:00
|
|
|
end
|
2013-03-12 06:37:53 -04:00
|
|
|
|
2015-06-13 18:24:51 -04:00
|
|
|
it { expect(@result).to eq false }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(project.namespace).to eq(user.namespace) }
|
2013-03-12 06:37:53 -04:00
|
|
|
end
|
|
|
|
|
2016-05-16 19:03:55 -04:00
|
|
|
context 'disallow transfering of project with tags' do
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: true)
|
|
|
|
stub_container_registry_tags('tag')
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { transfer_project(project, user, group) }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
2014-05-28 12:04:18 -04:00
|
|
|
context 'namespace -> not allowed namespace' do
|
|
|
|
before do
|
2015-07-02 10:47:15 -04:00
|
|
|
@result = transfer_project(project, user, group)
|
2014-05-28 12:04:18 -04:00
|
|
|
end
|
|
|
|
|
2015-06-13 18:24:51 -04:00
|
|
|
it { expect(@result).to eq false }
|
2015-02-12 13:17:35 -05:00
|
|
|
it { expect(project.namespace).to eq(user.namespace) }
|
2013-03-12 06:37:53 -04:00
|
|
|
end
|
2014-10-04 05:44:20 -04:00
|
|
|
|
2015-07-02 10:47:15 -04:00
|
|
|
def transfer_project(project, user, new_namespace)
|
|
|
|
Projects::TransferService.new(project, user).execute(new_namespace)
|
2014-10-04 05:44:20 -04:00
|
|
|
end
|
2016-04-13 14:28:10 -04:00
|
|
|
|
|
|
|
context 'visibility level' do
|
|
|
|
let(:internal_group) { create(:group, :internal) }
|
|
|
|
|
|
|
|
before { internal_group.add_owner(user) }
|
|
|
|
|
|
|
|
context 'when namespace visibility level < project visibility level' do
|
|
|
|
let(:public_project) { create(:project, :public, namespace: user.namespace) }
|
|
|
|
|
|
|
|
before { transfer_project(public_project, user, internal_group) }
|
|
|
|
|
|
|
|
it { expect(public_project.visibility_level).to eq(internal_group.visibility_level) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when namespace visibility level > project visibility level' do
|
|
|
|
let(:private_project) { create(:project, :private, namespace: user.namespace) }
|
|
|
|
|
|
|
|
before { transfer_project(private_project, user, internal_group) }
|
|
|
|
|
|
|
|
it { expect(private_project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE) }
|
|
|
|
end
|
|
|
|
end
|
2016-09-26 16:10:54 -04:00
|
|
|
|
|
|
|
context 'missing group labels applied to issues or merge requests' do
|
|
|
|
it 'delegates tranfer to Labels::TransferService' do
|
|
|
|
group.add_owner(user)
|
|
|
|
|
|
|
|
expect_any_instance_of(Labels::TransferService).to receive(:execute).once.and_call_original
|
|
|
|
|
|
|
|
transfer_project(project, user, group)
|
|
|
|
end
|
|
|
|
end
|
2013-03-12 06:37:53 -04:00
|
|
|
end
|