Skip to content
This repository
Browse code

fixed bug with nested resources within shallow scope

[#6372 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit adbae9aab8a439a824cf1612febb5918d0f4cf87 1 parent 94175c0
Dmitrii Samoilov german authored spastorino committed
2  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1199,7 +1199,7 @@ def namespace(path, options = {})
1199 1199 end
1200 1200
1201 1201 def shallow
1202   - scope(:shallow => true) do
  1202 + scope(:shallow => true, :shallow_path => @scope[:path]) do
1203 1203 yield
1204 1204 end
1205 1205 end
62 actionpack/test/dispatch/routing_test.rb
@@ -205,6 +205,14 @@ def self.call(params, request)
205 205 end
206 206 end
207 207
  208 + scope '/hello' do
  209 + shallow do
  210 + resources :notes do
  211 + resources :trackbacks
  212 + end
  213 + end
  214 + end
  215 +
208 216 resources :threads, :shallow => true do
209 217 resource :owner
210 218 resources :messages do
@@ -1676,6 +1684,60 @@ def test_shallow_nested_resources
1676 1684 end
1677 1685 end
1678 1686
  1687 + def test_shallow_nested_resources_within_scope
  1688 + with_test_routes do
  1689 +
  1690 + get '/hello/notes/1/trackbacks'
  1691 + assert_equal 'trackbacks#index', @response.body
  1692 + assert_equal '/hello/notes/1/trackbacks', note_trackbacks_path(:note_id => 1)
  1693 +
  1694 + get '/hello/notes/1/edit'
  1695 + assert_equal 'notes#edit', @response.body
  1696 + assert_equal '/hello/notes/1/edit', edit_note_path(:id => '1')
  1697 +
  1698 + get '/hello/notes/1/trackbacks/new'
  1699 + assert_equal 'trackbacks#new', @response.body
  1700 + assert_equal '/hello/notes/1/trackbacks/new', new_note_trackback_path(:note_id => 1)
  1701 +
  1702 + get '/hello/trackbacks/1'
  1703 + assert_equal 'trackbacks#show', @response.body
  1704 + assert_equal '/hello/trackbacks/1', trackback_path(:id => '1')
  1705 +
  1706 + get '/hello/trackbacks/1/edit'
  1707 + assert_equal 'trackbacks#edit', @response.body
  1708 + assert_equal '/hello/trackbacks/1/edit', edit_trackback_path(:id => '1')
  1709 +
  1710 + put '/hello/trackbacks/1'
  1711 + assert_equal 'trackbacks#update', @response.body
  1712 +
  1713 + post '/hello/notes/1/trackbacks'
  1714 + assert_equal 'trackbacks#create', @response.body
  1715 +
  1716 + delete '/hello/trackbacks/1'
  1717 + assert_equal 'trackbacks#destroy', @response.body
  1718 +
  1719 + get '/hello/notes'
  1720 + assert_equal 'notes#index', @response.body
  1721 +
  1722 + post '/hello/notes'
  1723 + assert_equal 'notes#create', @response.body
  1724 +
  1725 + get '/hello/notes/new'
  1726 + assert_equal 'notes#new', @response.body
  1727 + assert_equal '/hello/notes/new', new_note_path
  1728 +
  1729 + get '/hello/notes/1'
  1730 + assert_equal 'notes#show', @response.body
  1731 + assert_equal '/hello/notes/1', note_path(:id => 1)
  1732 +
  1733 + put '/hello/notes/1'
  1734 + assert_equal 'notes#update', @response.body
  1735 +
  1736 + delete '/hello/notes/1'
  1737 + assert_equal 'notes#destroy', @response.body
  1738 + end
  1739 + end
  1740 +
1679 1741 def test_custom_resource_routes_are_scoped
1680 1742 with_test_routes do
1681 1743 assert_equal '/customers/recent', recent_customers_path

0 comments on commit adbae9a

Please sign in to comment.
Something went wrong with that request. Please try again.