summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-04-05 15:41:00 +0200
committerBob Van Landuyt <bob@gitlab.com>2017-05-01 11:14:24 +0200
commit74fcccaab30ac0f9e11ed9a076c008ade13a50d0 (patch)
treee3341f6aa020659655b2b6941fe8660befe315bf /spec/validators
parent536f2bdfd17ac3bab38851de2973dd1c89dccc3f (diff)
downloadgitlab-ce-74fcccaab30ac0f9e11ed9a076c008ade13a50d0.tar.gz
Streamline the path validation in groups & projects
`Project` uses `ProjectPathValidator` which is now a `NamespaceValidator` that skips the format validation. That way we're sure we are using the same collection of reserved paths. I updated the path constraints to reflect the changes: We now allow some values that are only used on a top level namespace as a name for a nested group/project.
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/namespace_validator_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/validators/namespace_validator_spec.rb b/spec/validators/namespace_validator_spec.rb
index e21b8ef5abd..4b5dd59e048 100644
--- a/spec/validators/namespace_validator_spec.rb
+++ b/spec/validators/namespace_validator_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe NamespaceValidator do
+ let(:validator) { described_class.new(attributes: [:path]) }
describe 'RESERVED' do
it 'includes all the top level namespaces' do
all_top_level_routes = Rails.application.routes.routes.routes.
@@ -26,4 +27,36 @@ describe NamespaceValidator do
expect(described_class::WILDCARD_ROUTES).to include(*all_wildcard_paths)
end
end
+
+ describe '#validation_type' do
+ it 'uses top level validation for groups without parent' do
+ group = build(:group)
+
+ type = validator.validation_type(group)
+
+ expect(type).to eq(:top_level)
+ end
+
+ it 'uses wildcard validation for groups with a parent' do
+ group = build(:group, parent: create(:group))
+
+ type = validator.validation_type(group)
+
+ expect(type).to eq(:wildcard)
+ end
+
+ it 'uses wildcard validation for a project' do
+ project = build(:project)
+
+ type = validator.validation_type(project)
+
+ expect(type).to eq(:wildcard)
+ end
+
+ it 'uses strict validation for everything else' do
+ type = validator.validation_type(double)
+
+ expect(type).to eq(:strict)
+ end
+ end
end