aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDylan Waits <dylan@waits.io>2016-04-02 18:38:22 -0700
committerDylan Waits <dylan@waits.io>2016-04-03 17:44:11 -0700
commite09e600a48e525553767da5a1ec2e756fe62aac4 (patch)
treecadc52f3e55af4ca5c87bbb50389f00cea1d276e /actionpack
parent8040e55063abde6eeaac2702ca9961ce34a2d6c7 (diff)
downloadrails-e09e600a48e525553767da5a1ec2e756fe62aac4.tar.gz
rails-e09e600a48e525553767da5a1ec2e756fe62aac4.tar.bz2
rails-e09e600a48e525553767da5a1ec2e756fe62aac4.zip
Honor shallow: false on nested resources
Previously there was no way to place a non-shallow resource inside a parent with `shallow: true` set. Now you can set `shallow: false` on a nested child resource to generate normal (non-shallow) routes for it. Fixes #23890.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb5
-rw-r--r--actionpack/test/dispatch/routing_test.rb31
2 files changed, 35 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 16b430c36e..81ffea4d5d 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1362,6 +1362,8 @@ module ActionDispatch
# as a comment on a blog post like <tt>/posts/a-long-permalink/comments/1234</tt>
# to be shortened to just <tt>/comments/1234</tt>.
#
+ # Set shallow: false on a child resource to ignore a parent's shallow parameter.
+ #
# [:shallow_path]
# Prefixes nested shallow routes with the specified path.
#
@@ -1724,7 +1726,8 @@ to this:
return true
end
- if options.delete(:shallow)
+ if options[:shallow]
+ options.delete(:shallow)
shallow do
send(method, resources.pop, options, &block)
end
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 09830c0c46..dc9943bb13 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -2128,6 +2128,37 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal 'cards#destroy', @response.body
end
+ def test_shallow_false_inside_nested_shallow_resource
+ draw do
+ resources :blogs, shallow: true do
+ resources :posts do
+ resources :comments, shallow: false
+ resources :tags
+ end
+ end
+ end
+
+ get '/posts/1/comments'
+ assert_equal 'comments#index', @response.body
+ assert_equal '/posts/1/comments', post_comments_path('1')
+
+ get '/posts/1/comments/new'
+ assert_equal 'comments#new', @response.body
+ assert_equal '/posts/1/comments/new', new_post_comment_path('1')
+
+ get '/posts/1/comments/2'
+ assert_equal 'comments#show', @response.body
+ assert_equal '/posts/1/comments/2', post_comment_path('1', '2')
+
+ get '/posts/1/comments/2/edit'
+ assert_equal 'comments#edit', @response.body
+ assert_equal '/posts/1/comments/2/edit', edit_post_comment_path('1', '2')
+
+ get '/tags/3'
+ assert_equal 'tags#show', @response.body
+ assert_equal '/tags/3', tag_path('3')
+ end
+
def test_shallow_deeply_nested_resources
draw do
resources :blogs do