Only make deeply nested routes shallow when parent is shallow
Since `:shallow` may be set at any point in the resource nesting we should only make the new and collection routes shallow when the parent is shallow. This is a bit of a hack but until the mapper is refactored to an object graph instead of a hash of merged values it's the best we can do. Fixes #14684.
This commit is contained in:
parent
77252c332e
commit
e10f26f9e9
|
@ -1,9 +1,15 @@
|
||||||
|
* Only make deeply nested routes shallow when parent is shallow.
|
||||||
|
|
||||||
|
Fixes #14684.
|
||||||
|
|
||||||
|
*Andrew White*, *James Coglan*
|
||||||
|
|
||||||
* Append link to bad code to backtrace when exception is SyntaxError.
|
* Append link to bad code to backtrace when exception is SyntaxError.
|
||||||
|
|
||||||
*Boris Kuznetsov*
|
*Boris Kuznetsov*
|
||||||
|
|
||||||
* Swapped the parameters of assert_equal in `assert_select` so that the
|
* Swapped the parameters of assert_equal in `assert_select` so that the
|
||||||
proper values were printed correctly
|
proper values were printed correctly
|
||||||
|
|
||||||
Fixes #14422.
|
Fixes #14422.
|
||||||
|
|
||||||
|
|
|
@ -995,6 +995,7 @@ module ActionDispatch
|
||||||
@as = options[:as]
|
@as = options[:as]
|
||||||
@param = (options[:param] || :id).to_sym
|
@param = (options[:param] || :id).to_sym
|
||||||
@options = options
|
@options = options
|
||||||
|
@shallow = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_actions
|
def default_actions
|
||||||
|
@ -1055,6 +1056,13 @@ module ActionDispatch
|
||||||
"#{path}/:#{nested_param}"
|
"#{path}/:#{nested_param}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def shallow=(value)
|
||||||
|
@shallow = value
|
||||||
|
end
|
||||||
|
|
||||||
|
def shallow?
|
||||||
|
@shallow
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class SingletonResource < Resource #:nodoc:
|
class SingletonResource < Resource #:nodoc:
|
||||||
|
@ -1361,7 +1369,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
with_scope_level(:nested) do
|
with_scope_level(:nested) do
|
||||||
if shallow? && nesting_depth > 1
|
if shallow? && shallow_nesting_depth > 1
|
||||||
shallow_scope(parent_resource.nested_scope, nested_options) { yield }
|
shallow_scope(parent_resource.nested_scope, nested_options) { yield }
|
||||||
else
|
else
|
||||||
scope(parent_resource.nested_scope, nested_options) { yield }
|
scope(parent_resource.nested_scope, nested_options) { yield }
|
||||||
|
@ -1576,6 +1584,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_scope(kind, resource) #:nodoc:
|
def resource_scope(kind, resource) #:nodoc:
|
||||||
|
resource.shallow = @scope[:shallow]
|
||||||
old_resource, @scope[:scope_level_resource] = @scope[:scope_level_resource], resource
|
old_resource, @scope[:scope_level_resource] = @scope[:scope_level_resource], resource
|
||||||
@nesting.push(resource)
|
@nesting.push(resource)
|
||||||
|
|
||||||
|
@ -1600,6 +1609,10 @@ module ActionDispatch
|
||||||
@nesting.size
|
@nesting.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def shallow_nesting_depth #:nodoc:
|
||||||
|
@nesting.select(&:shallow?).size
|
||||||
|
end
|
||||||
|
|
||||||
def param_constraint? #:nodoc:
|
def param_constraint? #:nodoc:
|
||||||
@scope[:constraints] && @scope[:constraints][parent_resource.param].is_a?(Regexp)
|
@scope[:constraints] && @scope[:constraints][parent_resource.param].is_a?(Regexp)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue