summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-05-02 10:32:31 +0200
committerBob Van Landuyt <bob@gitlab.com>2017-05-02 10:47:01 +0200
commita035ebbe069fa6b203c279c8944b447f8fe896c5 (patch)
tree1584df4a1304e9ded6c0b127cb0be75ed2ae1da3 /spec/validators
parentc853dd6158af0f77721ce59c03f5f05e98eeadba (diff)
downloadgitlab-ce-a035ebbe069fa6b203c279c8944b447f8fe896c5.tar.gz
Update path validation & specs
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/dynamic_path_validator_spec.rb43
1 files changed, 40 insertions, 3 deletions
diff --git a/spec/validators/dynamic_path_validator_spec.rb b/spec/validators/dynamic_path_validator_spec.rb
index 4924706b88e..deeff477193 100644
--- a/spec/validators/dynamic_path_validator_spec.rb
+++ b/spec/validators/dynamic_path_validator_spec.rb
@@ -144,14 +144,19 @@ describe DynamicPathValidator do
end
end
- describe '.without_reserved_child_paths_regex' do
- it 'rejects paths containing a child reserved word' do
- subject = described_class.without_reserved_child_paths_regex
+ describe '.regex_excluding_child_paths' do
+ let(:subject) { described_class.without_reserved_child_paths_regex }
+ it 'rejects paths containing a child reserved word' do
expect(subject).not_to match('hello/group_members')
expect(subject).not_to match('hello/activity/in-the-middle')
expect(subject).not_to match('foo/bar1/refs/master/logs_tree')
end
+
+ it 'allows a child path on the top level' do
+ expect(subject).to match('activity/foo')
+ expect(subject).to match('avatar')
+ end
end
describe ".valid?" do
@@ -195,4 +200,36 @@ describe DynamicPathValidator do
expect(described_class.valid?(test_path)).to be_falsey
end
end
+
+ describe '#path_reserved_for_record?' do
+ it 'reserves a sub-group named activity' do
+ group = build(:group, :nested, path: 'activity')
+
+ expect(validator.path_reserved_for_record?(group, 'activity')).to be_truthy
+ end
+
+ it "doesn't reserve a project called activity" do
+ project = build(:project, path: 'activity')
+
+ expect(validator.path_reserved_for_record?(project, 'activity')).to be_falsey
+ end
+ end
+
+ describe '#validates_each' do
+ it 'adds a message when the path is not in the correct format' do
+ group = build(:group)
+
+ validator.validate_each(group, :path, "Path with spaces, and comma's!")
+
+ expect(group.errors[:path]).to include(Gitlab::Regex.namespace_regex_message)
+ end
+
+ it 'adds a message when the path is not in the correct format' do
+ group = build(:group, path: 'users')
+
+ validator.validate_each(group, :path, 'users')
+
+ expect(group.errors[:path]).to include('users is a reserved name')
+ end
+ end
end