diff options
author | Sam Ruby <rubys@intertwingly.net> | 2009-12-23 23:33:14 -0500 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-12-23 20:55:21 -0800 |
commit | aa3565f3a6327c947ded314525ba1d0674d5a71e (patch) | |
tree | 2afa31bf9d36ff008c497770815edd457d8bbd10 | |
parent | 84f1137ef87ff3c8e7cff5e8363d1f116b23fcae (diff) | |
download | rails-aa3565f3a6327c947ded314525ba1d0674d5a71e.tar.gz rails-aa3565f3a6327c947ded314525ba1d0674d5a71e.tar.bz2 rails-aa3565f3a6327c947ded314525ba1d0674d5a71e.zip |
Allow named_routes to be used with root, and with new DSL short-form.
The real use case it to make all of the following act the same:
root 'store#index', :as => 'store'
match '/' => 'store#index', :as => 'store'
match '/', :to => 'store#index', :as => 'store'
The test case provided deviates from this in order to demonstrate all three
forms in a single set of test routes.
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 15 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 9 |
2 files changed, 16 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 40e30bca6f..3eadb0e9fe 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -35,18 +35,17 @@ module ActionDispatch end def root(options = {}) - raise "Can't rename root to #{options[:as].inspect}: root is always named 'root'" if options.include?(:as) - match '/', options.merge(:as => :root) + match '/', options.reverse_merge(:as => :root) end def match(*args) - if args.one? && args.first.is_a?(Hash) - options = args.first - path = options.keys.first - options[:to] = options.delete(path) + options = args.extract_options! + + if args.empty? + path, to = options.find {|name,value| name.is_a?(String)} + options.merge!(:to => to).delete(path) if path else - path = args.first - options = args.extract_options! + path = args.first end conditions, defaults = {}, {} diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 7ca85a4201..82231cb3d9 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -111,6 +111,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end root :to => 'projects#index' + match '/info' => 'projects#info', :as => 'info' end end @@ -469,6 +470,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_index + with_test_routes do + assert_equal '/info', info_path + get '/info' + assert_equal 'projects#info', @response.body + end + end + private def with_test_routes real_routes, temp_routes = ActionController::Routing::Routes, Routes |