aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/journey
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-01-15 17:18:59 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2013-01-15 17:22:25 +0000
commitf1d8f2af72e21d41efd02488f1c2dcf829e17783 (patch)
tree00250bda5b8af7a81d16c621972e56b07191b18b /actionpack/test/journey
parent90d2802b71a6e89aedfe40564a37bd35f777e541 (diff)
downloadrails-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/journey')
-rw-r--r--actionpack/test/journey/route_test.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb
index 78608a5c6b..cbe6284714 100644
--- a/actionpack/test/journey/route_test.rb
+++ b/actionpack/test/journey/route_test.rb
@@ -6,18 +6,18 @@ module ActionDispatch
def test_initialize
app = Object.new
path = Path::Pattern.new '/:controller(/:action(/:id(.:format)))'
- defaults = Object.new
+ defaults = {}
route = Route.new("name", app, path, {}, defaults)
assert_equal app, route.app
assert_equal path, route.path
- assert_equal defaults, route.defaults
+ assert_same defaults, route.defaults
end
def test_route_adds_itself_as_memo
app = Object.new
path = Path::Pattern.new '/:controller(/:action(/:id(.:format)))'
- defaults = Object.new
+ defaults = {}
route = Route.new("name", app, path, {}, defaults)
route.ast.grep(Nodes::Terminal).each do |node|
@@ -82,11 +82,14 @@ module ActionDispatch
end
def test_score
+ constraints = {:required_defaults => [:controller, :action]}
+ defaults = {:controller=>"pages", :action=>"show"}
+
path = Path::Pattern.new "/page/:id(/:action)(.:format)"
- specific = Route.new "name", nil, path, {}, {:controller=>"pages", :action=>"show"}
+ specific = Route.new "name", nil, path, constraints, defaults
path = Path::Pattern.new "/:controller(/:action(/:id))(.:format)"
- generic = Route.new "name", nil, path, {}
+ generic = Route.new "name", nil, path, constraints
knowledge = {:id=>20, :controller=>"pages", :action=>"show"}