提交 1498a9cb 编写于 作者: B Bob Van Landuyt

Check `has_parent?` for determining validation type

上级 f7511caa
......@@ -220,6 +220,10 @@ class Namespace < ActiveRecord::Base
Project.inside_path(full_path)
end
def has_parent?
parent.present?
end
private
def repository_storage_paths
......
......@@ -74,7 +74,7 @@ class NamespaceValidator < ActiveModel::EachValidator
preview blob blame raw files create_dir find_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)
path_segments = full_path.split('/')
......@@ -120,8 +120,8 @@ class NamespaceValidator < ActiveModel::EachValidator
def validation_type(record)
case record
when Group
record.parent_id ? :wildcard : :top_level
when Namespace
record.has_parent? ? :wildcard : :top_level
when Project
:wildcard
else
......
......@@ -47,6 +47,7 @@ describe Namespace, models: true do
describe "Respond to" do
it { is_expected.to respond_to(:human_name) }
it { is_expected.to respond_to(:to_param) }
it { is_expected.to respond_to(:has_parent?) }
end
describe '#to_param' do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册