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

Allow root to be given in the resources scope without need to specify :on => collection.

This commit is contained in:
José Valim 2010-05-17 17:36:34 +02:00
parent 5371242384
commit 107c6381a0
2 changed files with 16 additions and 1 deletions

View file

@ -693,6 +693,11 @@ module ActionDispatch
super
end
def root(options={})
options[:on] ||= :collection if @scope[:scope_level] == :resources
super(options)
end
protected
def parent_resource #:nodoc:
@scope[:scope_level_resource]

View file

@ -186,6 +186,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
resources :products, :constraints => { :id => /\d{4}/ } do
root :to => "products#root"
get :favorite, :on => :collection
resources :images
end
@ -963,7 +965,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
get '/products/1'
assert_equal 'pass', @response.headers['X-Cascade']
get '/products'
assert_equal 'products#index', @response.body
assert_equal 'products#root', @response.body
get '/products/favorite'
assert_equal 'products#favorite', @response.body
get '/products/0001'
assert_equal 'products#show', @response.body
@ -981,6 +985,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
def test_root_works_in_the_resources_scope
get '/products'
assert_equal 'products#root', @response.body
assert_equal '/products', products_root_path
end
def test_module_scope
with_test_routes do
get '/token'