diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2014-04-11 10:26:23 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2014-04-11 10:26:23 +0100 |
commit | 142448259d7f450df49fdac06bf912edfecaa633 (patch) | |
tree | 2973e32dfe5545ab7d65707003a8d8e77acc55d5 /actionpack | |
parent | 856ffbe7058065a34a708fd5b398c0553f9f1f97 (diff) | |
parent | e10f26f9e90f2fe6c4cd18f70c1e559f2250da56 (diff) | |
download | rails-142448259d7f450df49fdac06bf912edfecaa633.tar.gz rails-142448259d7f450df49fdac06bf912edfecaa633.tar.bz2 rails-142448259d7f450df49fdac06bf912edfecaa633.zip |
Merge pull request #14684 from Futurelearn/jc-deep-nested-shallow-url-helper-bug
Add a failing test for a URL helper that was broken by a6b9ea2.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 10 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 15 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 18 |
3 files changed, 40 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index e70e0b5fa7..323b88721d 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -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. *Boris Kuznetsov* - + * Swapped the parameters of assert_equal in `assert_select` so that the - proper values were printed correctly + proper values were printed correctly Fixes #14422. diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 6f0b49cf28..77718a14c1 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -995,6 +995,7 @@ module ActionDispatch @as = options[:as] @param = (options[:param] || :id).to_sym @options = options + @shallow = false end def default_actions @@ -1055,6 +1056,13 @@ module ActionDispatch "#{path}/:#{nested_param}" end + def shallow=(value) + @shallow = value + end + + def shallow? + @shallow + end end class SingletonResource < Resource #:nodoc: @@ -1361,7 +1369,7 @@ module ActionDispatch end 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 } else scope(parent_resource.nested_scope, nested_options) { yield } @@ -1576,6 +1584,7 @@ module ActionDispatch end def resource_scope(kind, resource) #:nodoc: + resource.shallow = @scope[:shallow] old_resource, @scope[:scope_level_resource] = @scope[:scope_level_resource], resource @nesting.push(resource) @@ -1600,6 +1609,10 @@ module ActionDispatch @nesting.size end + def shallow_nesting_depth #:nodoc: + @nesting.select(&:shallow?).size + end + def param_constraint? #:nodoc: @scope[:constraints] && @scope[:constraints][parent_resource.param].is_a?(Regexp) end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index ab2f0ec8de..f74a0ef945 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -1994,6 +1994,24 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal 'cards#destroy', @response.body end + def test_shallow_deeply_nested_resources + draw do + resources :blogs do + resources :posts do + resources :comments, shallow: true + end + end + end + + get '/comments/1' + assert_equal 'comments#show', @response.body + + assert_equal '/comments/1', comment_path('1') + assert_equal '/blogs/new', new_blog_path + assert_equal '/blogs/1/posts/new', new_blog_post_path(:blog_id => 1) + assert_equal '/blogs/1/posts/2/comments/new', new_blog_post_comment_path(:blog_id => 1, :post_id => 2) + end + def test_shallow_nested_resources_within_scope draw do scope '/hello' do |