From 1498a9cb0fb4500737c9d9e88f38c0ddf2b42791 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Tue, 11 Apr 2017 16:21:52 +0200 Subject: Check `has_parent?` for determining validation type --- app/models/namespace.rb | 4 ++++ app/validators/namespace_validator.rb | 6 +++--- spec/models/namespace_spec.rb | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 9bfa731785f..1570470d63f 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -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 diff --git a/app/validators/namespace_validator.rb b/app/validators/namespace_validator.rb index 8a0e18612ec..ed71d5ad5b5 100644 --- a/app/validators/namespace_validator.rb +++ b/app/validators/namespace_validator.rb @@ -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 diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index e406d0a16bd..6775fd2f1b8 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -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 -- cgit v1.2.3