diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-04-13 18:50:36 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@gitlab.com> | 2017-05-01 11:14:24 +0200 |
commit | 579d8891d550cfbbcb433ed4966c6de37c710e83 (patch) | |
tree | bc91bd91ae5bdfd7a390b9c07fa553d102f50693 /spec/lib/gitlab/database/rename_reserved_paths_migration | |
parent | 7508ee56670dd960275b6438be91471020ea62ab (diff) | |
download | gitlab-ce-579d8891d550cfbbcb433ed4966c6de37c710e83.tar.gz |
Rename projects in a migrationhelper
Diffstat (limited to 'spec/lib/gitlab/database/rename_reserved_paths_migration')
-rw-r--r-- | spec/lib/gitlab/database/rename_reserved_paths_migration/namespaces_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/database/rename_reserved_paths_migration/projects_spec.rb | 76 |
2 files changed, 80 insertions, 38 deletions
diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/namespaces_spec.rb index 3e5f981c095..f6d95f04073 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/namespaces_spec.rb @@ -1,8 +1,6 @@ require 'spec_helper' describe Gitlab::Database::RenameReservedPathsMigration::Namespaces, :truncate do - let(:test_dir) { File.join(Rails.root, 'tmp', 'tests', 'rename_namespaces_test') } - let(:uploads_dir) { File.join(test_dir, 'public', 'uploads') } let(:subject) do ActiveRecord::Migration.new.extend( Gitlab::Database::RenameReservedPathsMigration @@ -10,10 +8,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::Namespaces, :truncate d end before do - FileUtils.remove_dir(test_dir) if File.directory?(test_dir) - FileUtils.mkdir_p(uploads_dir) - FileUtils.remove_dir(TestEnv.repos_path) if File.directory?(TestEnv.repos_path) - allow(subject).to receive(:uploads_dir).and_return(uploads_dir) allow(subject).to receive(:say) end @@ -44,8 +38,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::Namespaces, :truncate d root_namespace = create(:namespace, path: 'the-path') _other_path = create(:namespace, path: 'other') _child_namespace = create(:namespace, - path: 'the-path', - parent: create(:namespace)) + path: 'the-path', + parent: create(:namespace)) found_ids = subject.namespaces_for_paths(['the-path'], type: :top_level). map(&:id) @@ -87,32 +81,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::Namespaces, :truncate d end end - describe '#move_namespace_folders' do - it 'moves a namespace with files' do - source = File.join(uploads_dir, 'parent-group', 'sub-group') - FileUtils.mkdir_p(source) - destination = File.join(uploads_dir, 'parent-group', 'moved-group') - FileUtils.touch(File.join(source, 'test.txt')) - expected_file = File.join(destination, 'test.txt') - - subject.move_namespace_folders(uploads_dir, File.join('parent-group', 'sub-group'), File.join('parent-group', 'moved-group')) - - expect(File.exist?(expected_file)).to be(true) - end - - it 'moves a parent namespace uploads' do - source = File.join(uploads_dir, 'parent-group', 'sub-group') - FileUtils.mkdir_p(source) - destination = File.join(uploads_dir, 'moved-parent', 'sub-group') - FileUtils.touch(File.join(source, 'test.txt')) - expected_file = File.join(destination, 'test.txt') - - subject.move_namespace_folders(uploads_dir, 'parent-group', 'moved-parent') - - expect(File.exist?(expected_file)).to be(true) - end - end - describe "#child_ids_for_parent" do it "collects child ids for all levels" do parent = create(:namespace) @@ -148,15 +116,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::Namespaces, :truncate d end it "moves the uploads for the namespace" do - allow(subject).to receive(:move_namespace_folders).with(Settings.pages.path, "the-path", "the-path0") - expect(subject).to receive(:move_namespace_folders).with(uploads_dir, "the-path", "the-path0") + expect(subject).to receive(:move_uploads).with("the-path", "the-path0") subject.rename_namespace(namespace) end it "moves the pages for the namespace" do - allow(subject).to receive(:move_namespace_folders).with(uploads_dir, "the-path", "the-path0") - expect(subject).to receive(:move_namespace_folders).with(Settings.pages.path, "the-path", "the-path0") + expect(subject).to receive(:move_pages).with("the-path", "the-path0") subject.rename_namespace(namespace) end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/projects_spec.rb new file mode 100644 index 00000000000..7d3344faa10 --- /dev/null +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/projects_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe Gitlab::Database::RenameReservedPathsMigration::Projects, :truncate do + let(:subject) do + ActiveRecord::Migration.new.extend( + Gitlab::Database::RenameReservedPathsMigration + ) + end + + before do + allow(subject).to receive(:say) + end + + describe '#projects_for_paths' do + it 'includes the correct projects' do + project = create(:empty_project, path: 'THE-path') + _other_project = create(:empty_project) + + result_ids = subject.projects_for_paths(['the-PATH']).map(&:id) + + expect(result_ids).to contain_exactly(project.id) + end + end + + describe '#rename_project' do + let(:project) do + create(:empty_project, + path: 'the-path', + namespace: create(:namespace, path: 'known-parent' )) + end + + it 'renames path & route for the project' do + expect(subject).to receive(:rename_path_for_routable). + with(project). + and_call_original + + subject.rename_project(project) + end + + it 'moves the wiki & the repo' do + expect(subject).to receive(:move_repository). + with(project, 'known-parent/the-path.wiki', 'known-parent/the-path0.wiki') + expect(subject).to receive(:move_repository). + with(project, 'known-parent/the-path', 'known-parent/the-path0') + + subject.rename_project(project) + end + + it 'moves uploads' do + expect(subject).to receive(:move_uploads). + with('known-parent/the-path', 'known-parent/the-path0') + + subject.rename_project(project) + end + + it 'moves pages' do + expect(subject).to receive(:move_pages). + with('known-parent/the-path', 'known-parent/the-path0') + + subject.rename_project(project) + end + end + + describe '#move_repository' do + let(:known_parent) { create(:namespace, path: 'known-parent') } + let(:project) { create(:project, path: 'the-path', namespace: known_parent) } + + it 'moves the repository for a project' do + expected_path = File.join(TestEnv.repos_path, 'known-parent', 'new-repo.git') + + subject.move_repository(project, 'known-parent/the-path', 'known-parent/new-repo') + + expect(File.directory?(expected_path)).to be(true) + end + end +end |