Commit 1498a9cb authored by Bob Van Landuyt's avatar Bob Van Landuyt

Check `has_parent?` for determining validation type

parent f7511caa
...@@ -220,6 +220,10 @@ class Namespace < ActiveRecord::Base ...@@ -220,6 +220,10 @@ class Namespace < ActiveRecord::Base
Project.inside_path(full_path) Project.inside_path(full_path)
end end
def has_parent?
parent.present?
end
private private
def repository_storage_paths def repository_storage_paths
......
...@@ -74,7 +74,7 @@ class NamespaceValidator < ActiveModel::EachValidator ...@@ -74,7 +74,7 @@ class NamespaceValidator < ActiveModel::EachValidator
preview blob blame raw files create_dir find_file preview blob blame raw files create_dir find_file
artifacts graphs refs badges objects folders file]) artifacts graphs refs badges objects folders file])
STRICT_RESERVED = (TOP_LEVEL_ROUTES | WILDCARD_ROUTES) STRICT_RESERVED = (TOP_LEVEL_ROUTES | WILDCARD_ROUTES).freeze
def self.valid_full_path?(full_path) def self.valid_full_path?(full_path)
path_segments = full_path.split('/') path_segments = full_path.split('/')
...@@ -120,8 +120,8 @@ class NamespaceValidator < ActiveModel::EachValidator ...@@ -120,8 +120,8 @@ class NamespaceValidator < ActiveModel::EachValidator
def validation_type(record) def validation_type(record)
case record case record
when Group when Namespace
record.parent_id ? :wildcard : :top_level record.has_parent? ? :wildcard : :top_level
when Project when Project
:wildcard :wildcard
else else
......
...@@ -47,6 +47,7 @@ describe Namespace, models: true do ...@@ -47,6 +47,7 @@ describe Namespace, models: true do
describe "Respond to" do describe "Respond to" do
it { is_expected.to respond_to(:human_name) } it { is_expected.to respond_to(:human_name) }
it { is_expected.to respond_to(:to_param) } it { is_expected.to respond_to(:to_param) }
it { is_expected.to respond_to(:has_parent?) }
end end
describe '#to_param' do describe '#to_param' do
......
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