From 3760a7c230512fef8643bbd078e59ad20787d591 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Fri, 12 May 2017 17:10:05 +0200 Subject: [PATCH 1/2] Only rename namespaces and projects with an invalid path For exact matches, not namespaces that end with an invalid path --- .../v1/rename_base.rb | 2 +- .../v1/rename_namespaces_spec.rb | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb index de4e6e7c404..95606290486 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb @@ -15,7 +15,7 @@ module Gitlab end def path_patterns - @path_patterns ||= paths.map { |path| "%#{path}" } + @path_patterns ||= paths.map { |path| ["%/#{path}", "#{path}"] }.flatten end def rename_path_for_routable(routable) diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb index a25c5da488a..ec444942804 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_namespaces_spec.rb @@ -23,6 +23,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do found_ids = subject.namespaces_for_paths(type: :child). map(&:id) + expect(found_ids).to contain_exactly(child.id) end end @@ -39,6 +40,22 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do found_ids = subject.namespaces_for_paths(type: :child). map(&:id) + + expect(found_ids).to contain_exactly(namespace.id) + end + + it 'has no namespaces that look the same' do + _root_namespace = create(:namespace, path: 'THE-path') + _similar_path = create(:namespace, + path: 'not-really-the-path', + parent: create(:namespace)) + namespace = create(:namespace, + path: 'the-path', + parent: create(:namespace)) + + found_ids = subject.namespaces_for_paths(type: :child). + map(&:id) + expect(found_ids).to contain_exactly(namespace.id) end end @@ -53,6 +70,20 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do found_ids = subject.namespaces_for_paths(type: :top_level). map(&:id) + + expect(found_ids).to contain_exactly(root_namespace.id) + end + + it 'has no namespaces that just look the same' do + root_namespace = create(:namespace, path: 'the-path') + _similar_path = create(:namespace, path: 'not-really-the-path') + _child_namespace = create(:namespace, + path: 'the-path', + parent: create(:namespace)) + + found_ids = subject.namespaces_for_paths(type: :top_level). + map(&:id) + expect(found_ids).to contain_exactly(root_namespace.id) end end From 48ffec9e74ad7ac381936d61f73cef86d9919513 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 12 May 2017 16:00:18 +0000 Subject: [PATCH 2/2] Update rename_base.rb --- .../database/rename_reserved_paths_migration/v1/rename_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb index 95606290486..5397877b5d5 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb @@ -15,7 +15,7 @@ module Gitlab end def path_patterns - @path_patterns ||= paths.map { |path| ["%/#{path}", "#{path}"] }.flatten + @path_patterns ||= paths.flat_map { |path| ["%/#{path}", path] } end def rename_path_for_routable(routable)