Commit 2e2a63c8 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Rename child namespaces in migrationhelpers

parent 08b1bc34
...@@ -23,6 +23,7 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration ...@@ -23,6 +23,7 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration
notification_settings notification_settings
oauth oauth
sent_notifications sent_notifications
unicorn_test
uploads uploads
users users
] ]
...@@ -33,9 +34,19 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration ...@@ -33,9 +34,19 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration
info/lfs/objects info/lfs/objects
] ]
DISSALLOWED_GROUP_PATHS = %w[
activity
avatar
group_members
labels
milestones
subgroups
]
def up def up
rename_root_paths(DISALLOWED_ROOT_PATHS) rename_root_paths(DISALLOWED_ROOT_PATHS)
rename_wildcard_paths(DISALLOWED_WILDCARD_PATHS) rename_wildcard_paths(DISALLOWED_WILDCARD_PATHS)
rename_child_paths(DISSALLOWED_GROUP_PATHS)
end end
def down def down
......
...@@ -7,11 +7,16 @@ module Gitlab ...@@ -7,11 +7,16 @@ module Gitlab
end end
def rename_wildcard_paths(one_or_more_paths) def rename_wildcard_paths(one_or_more_paths)
rename_child_paths(one_or_more_paths)
paths = Array(one_or_more_paths) paths = Array(one_or_more_paths)
RenameNamespaces.new(paths, self).rename_namespaces(type: :wildcard)
RenameProjects.new(paths, self).rename_projects RenameProjects.new(paths, self).rename_projects
end end
def rename_child_paths(one_or_more_paths)
paths = Array(one_or_more_paths)
RenameNamespaces.new(paths, self).rename_namespaces(type: :child)
end
def rename_root_paths(paths) def rename_root_paths(paths)
paths = Array(paths) paths = Array(paths)
RenameNamespaces.new(paths, self).rename_namespaces(type: :top_level) RenameNamespaces.new(paths, self).rename_namespaces(type: :top_level)
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
def namespaces_for_paths(type:) def namespaces_for_paths(type:)
namespaces = case type namespaces = case type
when :wildcard when :child
MigrationClasses::Namespace.where.not(parent_id: nil) MigrationClasses::Namespace.where.not(parent_id: nil)
when :top_level when :top_level
MigrationClasses::Namespace.where(parent_id: nil) MigrationClasses::Namespace.where(parent_id: nil)
......
...@@ -21,13 +21,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do ...@@ -21,13 +21,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do
parent = create(:namespace, path: 'parent') parent = create(:namespace, path: 'parent')
child = create(:namespace, path: 'the-path', parent: parent) child = create(:namespace, path: 'the-path', parent: parent)
found_ids = subject.namespaces_for_paths(type: :wildcard). found_ids = subject.namespaces_for_paths(type: :child).
map(&:id) map(&:id)
expect(found_ids).to contain_exactly(child.id) expect(found_ids).to contain_exactly(child.id)
end end
end end
context 'for wildcard namespaces' do context 'for child namespaces' do
it 'only returns child namespaces with the correct path' do it 'only returns child namespaces with the correct path' do
_root_namespace = create(:namespace, path: 'THE-path') _root_namespace = create(:namespace, path: 'THE-path')
_other_path = create(:namespace, _other_path = create(:namespace,
...@@ -37,7 +37,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do ...@@ -37,7 +37,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do
path: 'the-path', path: 'the-path',
parent: create(:namespace)) parent: create(:namespace))
found_ids = subject.namespaces_for_paths(type: :wildcard). found_ids = subject.namespaces_for_paths(type: :child).
map(&:id) map(&:id)
expect(found_ids).to contain_exactly(namespace.id) expect(found_ids).to contain_exactly(namespace.id)
end end
...@@ -165,7 +165,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do ...@@ -165,7 +165,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces do
expect(subject).to receive(:rename_namespace). expect(subject).to receive(:rename_namespace).
with(migration_namespace(child_namespace)) with(migration_namespace(child_namespace))
subject.rename_namespaces(type: :wildcard) subject.rename_namespaces(type: :child)
end end
end end
end end
require 'spec_helper' require 'spec_helper'
describe Gitlab::Database::RenameReservedPathsMigration::V1 do shared_examples 'renames child namespaces' do |type|
let(:subject) { FakeRenameReservedPathMigrationV1.new } it 'renames namespaces' do
before do
allow(subject).to receive(:say)
end
describe '#rename_wildcard_paths' do
it 'should rename namespaces' do
rename_namespaces = double rename_namespaces = double
expect(described_class::RenameNamespaces). expect(described_class::RenameNamespaces).
to receive(:new).with(['first-path', 'second-path'], subject). to receive(:new).with(['first-path', 'second-path'], subject).
and_return(rename_namespaces) and_return(rename_namespaces)
expect(rename_namespaces).to receive(:rename_namespaces). expect(rename_namespaces).to receive(:rename_namespaces).
with(type: :wildcard) with(type: :child)
subject.rename_wildcard_paths(['first-path', 'second-path']) subject.rename_wildcard_paths(['first-path', 'second-path'])
end end
end
describe Gitlab::Database::RenameReservedPathsMigration::V1 do
let(:subject) { FakeRenameReservedPathMigrationV1.new }
before do
allow(subject).to receive(:say)
end
describe '#rename_child_paths' do
it_behaves_like 'renames child namespaces'
end
describe '#rename_wildcard_paths' do
it_behaves_like 'renames child namespaces'
it 'should rename projects' do it 'should rename projects' do
rename_projects = double rename_projects = double
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment