1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #24405 from waits/shallow-false

Honor shallow: false on nested resources
This commit is contained in:
Rafael França 2019-04-02 19:32:13 -04:00 committed by GitHub
commit 798f175c65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View file

@ -1402,6 +1402,8 @@ module ActionDispatch
# as a comment on a blog post like <tt>/posts/a-long-permalink/comments/1234</tt> # 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>. # 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] # [:shallow_path]
# Prefixes nested shallow routes with the specified path. # Prefixes nested shallow routes with the specified path.
# #
@ -1672,7 +1674,8 @@ module ActionDispatch
return true return true
end end
if options.delete(:shallow) if options[:shallow]
options.delete(:shallow)
shallow do shallow do
send(method, resources.pop, options, &block) send(method, resources.pop, options, &block)
end end

View file

@ -2200,6 +2200,37 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal "cards#destroy", @response.body assert_equal "cards#destroy", @response.body
end 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 def test_shallow_deeply_nested_resources
draw do draw do
resources :blogs do resources :blogs do