diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-01-15 17:18:59 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-01-15 17:22:25 +0000 |
commit | f1d8f2af72e21d41efd02488f1c2dcf829e17783 (patch) | |
tree | 00250bda5b8af7a81d16c621972e56b07191b18b /actionpack/test/dispatch/routing_test.rb | |
parent | 90d2802b71a6e89aedfe40564a37bd35f777e541 (diff) | |
download | rails-f1d8f2af72e21d41efd02488f1c2dcf829e17783.tar.gz rails-f1d8f2af72e21d41efd02488f1c2dcf829e17783.tar.bz2 rails-f1d8f2af72e21d41efd02488f1c2dcf829e17783.zip |
Change the behavior of route defaults
This commit changes route defaults so that explicit defaults are no
longer required where the key is not part of the path. For example:
resources :posts, bucket_type: 'posts'
will be required whenever constructing the url from a hash such as a
functional test or using url_for directly. However using the explicit
form alters the behavior so it's not required:
resources :projects, defaults: { bucket_type: 'projects' }
This changes existing behavior slightly in that any routes which
only differ in their defaults will match the first route rather
than the closest match.
Closes #8814
Diffstat (limited to 'actionpack/test/dispatch/routing_test.rb')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 2d34a0f6b1..da7474e73c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3300,3 +3300,31 @@ class TestPortConstraints < ActionDispatch::IntegrationTest assert_response :success end end + +class TestRouteDefaults < ActionDispatch::IntegrationTest + stub_controllers do |routes| + Routes = routes + Routes.draw do + resources :posts, bucket_type: 'post' + resources :projects, defaults: { bucket_type: 'project' } + end + end + + def app + Routes + end + + include Routes.url_helpers + + def test_route_options_are_required_for_url_for + assert_raises(ActionController::UrlGenerationError) do + assert_equal '/posts/1', url_for(controller: 'posts', action: 'show', id: 1, only_path: true) + end + + assert_equal '/posts/1', url_for(controller: 'posts', action: 'show', id: 1, bucket_type: 'post', only_path: true) + end + + def test_route_defaults_are_not_required_for_url_for + assert_equal '/projects/1', url_for(controller: 'projects', action: 'show', id: 1, only_path: true) + end +end |