Merge branch 'bvl-validate-path-update' into 'master'

Rebuild the dynamic path before validating it

Closes #33746

See merge request !12213
This commit is contained in:
Douwe Maan 2017-06-21 15:49:27 +00:00
commit b303932ac9
3 changed files with 18 additions and 9 deletions

View File

@ -107,6 +107,14 @@ module Routable
RequestStore[key] ||= uncached_full_path RequestStore[key] ||= uncached_full_path
end end
def build_full_path
if parent && path
parent.full_path + '/' + path
else
path
end
end
private private
def uncached_full_path def uncached_full_path
@ -135,14 +143,6 @@ module Routable
end end
end end
def build_full_path
if parent && path
parent.full_path + '/' + path
else
path
end
end
def update_route def update_route
prepare_route prepare_route
route.save route.save

View File

@ -26,7 +26,7 @@ class DynamicPathValidator < ActiveModel::EachValidator
end end
def path_valid_for_record?(record, value) 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 return true unless full_path

View File

@ -84,5 +84,14 @@ describe DynamicPathValidator do
expect(group.errors[:path]).to include('users is a reserved name') expect(group.errors[:path]).to include('users is a reserved name')
end 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
end end