summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-11-03 19:48:15 +0100
committerDouwe Maan <douwe@selenight.nl>2017-11-06 14:46:53 +0100
commita10925e1c37e7dab19de346c553311adfaccb86c (patch)
treeee211cc4bc6a830284a23583cd3d06e529793b10 /spec/validators
parent97b80fefeb5da20798423b62b63fa9faa08ac118 (diff)
downloadgitlab-ce-a10925e1c37e7dab19de346c553311adfaccb86c.tar.gz
Reallow project paths ending in periodsdm-reallow-project-path-ending-in-period
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/dynamic_path_validator_spec.rb97
-rw-r--r--spec/validators/namespace_path_validator_spec.rb38
-rw-r--r--spec/validators/project_path_validator_spec.rb38
-rw-r--r--spec/validators/user_path_validator_spec.rb38
4 files changed, 114 insertions, 97 deletions
diff --git a/spec/validators/dynamic_path_validator_spec.rb b/spec/validators/dynamic_path_validator_spec.rb
deleted file mode 100644
index 08e1c5a728a..00000000000
--- a/spec/validators/dynamic_path_validator_spec.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-require 'spec_helper'
-
-describe DynamicPathValidator do
- let(:validator) { described_class.new(attributes: [:path]) }
-
- def expect_handles_invalid_utf8
- expect { yield('\255invalid') }.to be_falsey
- end
-
- describe '.valid_user_path' do
- it 'handles invalid utf8' do
- expect(described_class.valid_user_path?("a\0weird\255path")).to be_falsey
- end
- end
-
- describe '.valid_group_path' do
- it 'handles invalid utf8' do
- expect(described_class.valid_group_path?("a\0weird\255path")).to be_falsey
- end
- end
-
- describe '.valid_project_path' do
- it 'handles invalid utf8' do
- expect(described_class.valid_project_path?("a\0weird\255path")).to be_falsey
- end
- end
-
- describe '#path_valid_for_record?' do
- context 'for project' do
- it 'calls valid_project_path?' do
- project = build(:project, path: 'activity')
-
- expect(described_class).to receive(:valid_project_path?).with(project.full_path).and_call_original
-
- expect(validator.path_valid_for_record?(project, 'activity')).to be_truthy
- end
- end
-
- context 'for group' do
- it 'calls valid_group_path?' do
- group = build(:group, :nested, path: 'activity')
-
- expect(described_class).to receive(:valid_group_path?).with(group.full_path).and_call_original
-
- expect(validator.path_valid_for_record?(group, 'activity')).to be_falsey
- end
- end
-
- context 'for user' do
- it 'calls valid_user_path?' do
- user = build(:user, username: 'activity')
-
- expect(described_class).to receive(:valid_user_path?).with(user.full_path).and_call_original
-
- expect(validator.path_valid_for_record?(user, 'activity')).to be_truthy
- end
- end
-
- context 'for user namespace' do
- it 'calls valid_user_path?' do
- user = create(:user, username: 'activity')
- namespace = user.namespace
-
- expect(described_class).to receive(:valid_user_path?).with(namespace.full_path).and_call_original
-
- expect(validator.path_valid_for_record?(namespace, 'activity')).to be_truthy
- end
- 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::PathRegex.namespace_format_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
-
- it 'updating to an invalid path is not allowed' do
- project = create(:project)
- project.path = 'update'
-
- validator.validate_each(project, :path, 'update')
-
- expect(project.errors[:path]).to include('update is a reserved name')
- end
- end
-end
diff --git a/spec/validators/namespace_path_validator_spec.rb b/spec/validators/namespace_path_validator_spec.rb
new file mode 100644
index 00000000000..61e2845f35f
--- /dev/null
+++ b/spec/validators/namespace_path_validator_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe NamespacePathValidator do
+ let(:validator) { described_class.new(attributes: [:path]) }
+
+ describe '.valid_path?' do
+ it 'handles invalid utf8' do
+ expect(described_class.valid_path?("a\0weird\255path")).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::PathRegex.namespace_format_message)
+ end
+
+ it 'adds a message when the path is reserved when creating' do
+ group = build(:group, path: 'help')
+
+ validator.validate_each(group, :path, 'help')
+
+ expect(group.errors[:path]).to include('help is a reserved name')
+ end
+
+ it 'adds a message when the path is reserved when updating' do
+ group = create(:group)
+ group.path = 'help'
+
+ validator.validate_each(group, :path, 'help')
+
+ expect(group.errors[:path]).to include('help is a reserved name')
+ end
+ end
+end
diff --git a/spec/validators/project_path_validator_spec.rb b/spec/validators/project_path_validator_spec.rb
new file mode 100644
index 00000000000..8bb5e72dc22
--- /dev/null
+++ b/spec/validators/project_path_validator_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe ProjectPathValidator do
+ let(:validator) { described_class.new(attributes: [:path]) }
+
+ describe '.valid_path?' do
+ it 'handles invalid utf8' do
+ expect(described_class.valid_path?("a\0weird\255path")).to be_falsey
+ end
+ end
+
+ describe '#validates_each' do
+ it 'adds a message when the path is not in the correct format' do
+ project = build(:project)
+
+ validator.validate_each(project, :path, "Path with spaces, and comma's!")
+
+ expect(project.errors[:path]).to include(Gitlab::PathRegex.project_path_format_message)
+ end
+
+ it 'adds a message when the path is reserved when creating' do
+ project = build(:project, path: 'blob')
+
+ validator.validate_each(project, :path, 'blob')
+
+ expect(project.errors[:path]).to include('blob is a reserved name')
+ end
+
+ it 'adds a message when the path is reserved when updating' do
+ project = create(:project)
+ project.path = 'blob'
+
+ validator.validate_each(project, :path, 'blob')
+
+ expect(project.errors[:path]).to include('blob is a reserved name')
+ end
+ end
+end
diff --git a/spec/validators/user_path_validator_spec.rb b/spec/validators/user_path_validator_spec.rb
new file mode 100644
index 00000000000..a46089cc24f
--- /dev/null
+++ b/spec/validators/user_path_validator_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe UserPathValidator do
+ let(:validator) { described_class.new(attributes: [:username]) }
+
+ describe '.valid_path?' do
+ it 'handles invalid utf8' do
+ expect(described_class.valid_path?("a\0weird\255path")).to be_falsey
+ end
+ end
+
+ describe '#validates_each' do
+ it 'adds a message when the path is not in the correct format' do
+ user = build(:user)
+
+ validator.validate_each(user, :username, "Path with spaces, and comma's!")
+
+ expect(user.errors[:username]).to include(Gitlab::PathRegex.namespace_format_message)
+ end
+
+ it 'adds a message when the path is reserved when creating' do
+ user = build(:user, username: 'help')
+
+ validator.validate_each(user, :username, 'help')
+
+ expect(user.errors[:username]).to include('help is a reserved name')
+ end
+
+ it 'adds a message when the path is reserved when updating' do
+ user = create(:user)
+ user.username = 'help'
+
+ validator.validate_each(user, :username, 'help')
+
+ expect(user.errors[:username]).to include('help is a reserved name')
+ end
+ end
+end