2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-06 10:09:03 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::ProjectTransfer do
|
2015-10-06 10:09:03 -04:00
|
|
|
before do
|
|
|
|
@root_dir = File.join(Rails.root, "public", "uploads")
|
2017-07-25 13:09:00 -04:00
|
|
|
@project_transfer = described_class.new
|
2015-12-18 06:40:34 -05:00
|
|
|
allow(@project_transfer).to receive(:root_dir).and_return(@root_dir)
|
2015-10-06 10:09:03 -04:00
|
|
|
|
|
|
|
@project_path_was = "test_project_was"
|
|
|
|
@project_path = "test_project"
|
|
|
|
@namespace_path_was = "test_namespace_was"
|
|
|
|
@namespace_path = "test_namespace"
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm_rf([
|
|
|
|
File.join(@root_dir, @namespace_path),
|
|
|
|
File.join(@root_dir, @namespace_path_was)
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#move_project' do
|
|
|
|
it "moves project upload to another namespace" do
|
2018-03-09 12:17:14 -05:00
|
|
|
path_to_be_moved = File.join(@root_dir, @namespace_path_was, @project_path)
|
|
|
|
expected_path = File.join(@root_dir, @namespace_path, @project_path)
|
|
|
|
FileUtils.mkdir_p(path_to_be_moved)
|
|
|
|
|
2015-12-18 06:40:34 -05:00
|
|
|
@project_transfer.move_project(@project_path, @namespace_path_was, @namespace_path)
|
2015-10-06 10:09:03 -04:00
|
|
|
|
|
|
|
expect(Dir.exist?(expected_path)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-08 17:16:21 -05:00
|
|
|
describe '#move_namespace' do
|
|
|
|
context 'when moving namespace from root into another namespace' do
|
|
|
|
it "moves namespace projects' upload" do
|
|
|
|
child_namespace = 'test_child_namespace'
|
2018-03-09 12:17:14 -05:00
|
|
|
path_to_be_moved = File.join(@root_dir, child_namespace, @project_path)
|
|
|
|
expected_path = File.join(@root_dir, @namespace_path, child_namespace, @project_path)
|
|
|
|
FileUtils.mkdir_p(path_to_be_moved)
|
|
|
|
|
2018-03-08 17:16:21 -05:00
|
|
|
@project_transfer.move_namespace(child_namespace, nil, @namespace_path)
|
|
|
|
|
|
|
|
expect(Dir.exist?(expected_path)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving namespace from one parent to another' do
|
|
|
|
it "moves namespace projects' upload" do
|
|
|
|
child_namespace = 'test_child_namespace'
|
2018-03-09 12:17:14 -05:00
|
|
|
path_to_be_moved = File.join(@root_dir, @namespace_path_was, child_namespace, @project_path)
|
|
|
|
expected_path = File.join(@root_dir, @namespace_path, child_namespace, @project_path)
|
|
|
|
FileUtils.mkdir_p(path_to_be_moved)
|
|
|
|
|
2018-03-08 17:16:21 -05:00
|
|
|
@project_transfer.move_namespace(child_namespace, @namespace_path_was, @namespace_path)
|
|
|
|
|
|
|
|
expect(Dir.exist?(expected_path)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving namespace from having a parent to root' do
|
|
|
|
it "moves namespace projects' upload" do
|
|
|
|
child_namespace = 'test_child_namespace'
|
2018-03-09 12:17:14 -05:00
|
|
|
path_to_be_moved = File.join(@root_dir, @namespace_path_was, child_namespace, @project_path)
|
|
|
|
expected_path = File.join(@root_dir, child_namespace, @project_path)
|
|
|
|
FileUtils.mkdir_p(path_to_be_moved)
|
|
|
|
|
2018-03-08 17:16:21 -05:00
|
|
|
@project_transfer.move_namespace(child_namespace, @namespace_path_was, nil)
|
|
|
|
|
|
|
|
expect(Dir.exist?(expected_path)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-06 10:09:03 -04:00
|
|
|
describe '#rename_project' do
|
|
|
|
it "renames project" do
|
2018-03-09 12:17:14 -05:00
|
|
|
path_to_be_moved = File.join(@root_dir, @namespace_path, @project_path_was)
|
|
|
|
expected_path = File.join(@root_dir, @namespace_path, @project_path)
|
|
|
|
FileUtils.mkdir_p(path_to_be_moved)
|
|
|
|
|
2015-12-18 06:40:34 -05:00
|
|
|
@project_transfer.rename_project(@project_path_was, @project_path, @namespace_path)
|
2015-10-06 10:09:03 -04:00
|
|
|
|
|
|
|
expect(Dir.exist?(expected_path)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#rename_namespace' do
|
|
|
|
it "renames namespace" do
|
2018-03-09 12:17:14 -05:00
|
|
|
path_to_be_moved = File.join(@root_dir, @namespace_path_was, @project_path)
|
|
|
|
expected_path = File.join(@root_dir, @namespace_path, @project_path)
|
|
|
|
FileUtils.mkdir_p(path_to_be_moved)
|
|
|
|
|
2015-12-18 06:40:34 -05:00
|
|
|
@project_transfer.rename_namespace(@namespace_path_was, @namespace_path)
|
2015-10-06 10:09:03 -04:00
|
|
|
|
|
|
|
expect(Dir.exist?(expected_path)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|