summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-06-21 15:49:27 +0000
committerDouwe Maan <douwe@gitlab.com>2017-06-21 15:49:27 +0000
commitb303932ac973822c6c5f1bb20aec6a7729a40145 (patch)
tree72eb3f104a1fc82d09415eb82105678a82d94ba1
parentb5c3ad759342e61a597c32b62151d4ad076d4559 (diff)
parent79393a351db47afa0df3588b5cdf9fb254c75282 (diff)
downloadgitlab-ce-b303932ac973822c6c5f1bb20aec6a7729a40145.tar.gz
Merge branch 'bvl-validate-path-update' into 'master'
Rebuild the dynamic path before validating it Closes #33746 See merge request !12213
-rw-r--r--app/models/concerns/routable.rb16
-rw-r--r--app/validators/dynamic_path_validator.rb2
-rw-r--r--spec/validators/dynamic_path_validator_spec.rb9
3 files changed, 18 insertions, 9 deletions
diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb
index 63d02b76f6b..ec7796a9dbb 100644
--- a/app/models/concerns/routable.rb
+++ b/app/models/concerns/routable.rb
@@ -107,6 +107,14 @@ module Routable
RequestStore[key] ||= uncached_full_path
end
+ def build_full_path
+ if parent && path
+ parent.full_path + '/' + path
+ else
+ path
+ end
+ end
+
private
def uncached_full_path
@@ -135,14 +143,6 @@ module Routable
end
end
- def build_full_path
- if parent && path
- parent.full_path + '/' + path
- else
- path
- end
- end
-
def update_route
prepare_route
route.save
diff --git a/app/validators/dynamic_path_validator.rb b/app/validators/dynamic_path_validator.rb
index 27ac60637fd..4688aabc2a8 100644
--- a/app/validators/dynamic_path_validator.rb
+++ b/app/validators/dynamic_path_validator.rb
@@ -26,7 +26,7 @@ class DynamicPathValidator < ActiveModel::EachValidator
end
def path_valid_for_record?(record, value)
- full_path = record.respond_to?(:full_path) ? record.full_path : value
+ full_path = record.respond_to?(:build_full_path) ? record.build_full_path : value
return true unless full_path
diff --git a/spec/validators/dynamic_path_validator_spec.rb b/spec/validators/dynamic_path_validator_spec.rb
index 8dbf3eecd23..8bd5306ff98 100644
--- a/spec/validators/dynamic_path_validator_spec.rb
+++ b/spec/validators/dynamic_path_validator_spec.rb
@@ -84,5 +84,14 @@ describe DynamicPathValidator do
expect(group.errors[:path]).to include('users is a reserved name')
end
+
+ it 'updating to an invalid path is not allowed' do
+ project = create(:empty_project)
+ project.path = 'update'
+
+ validator.validate_each(project, :path, 'update')
+
+ expect(project.errors[:path]).to include('update is a reserved name')
+ end
end
end