Allow symbols on routes declaration (:controller and :action values) [#2828 state:resolved]

Signed-off-by: Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>
This commit is contained in:
Jesús García Sáez
2009-06-23 22:54:32 +02:00
committed by Yehuda Katz + Carl Lerche
parent 0fbf458b6c
commit fc6077d76e
2 changed files with 11 additions and 0 deletions

View File

@@ -305,6 +305,7 @@ module ActionController
end
def add_route(path, options = {})
options.each { |k, v| options[k] = v.to_s if [:controller, :action].include?(k) && v.is_a?(Symbol) }
route = builder.build(path, options)
routes << route
route

View File

@@ -2492,6 +2492,16 @@ class RouteSetTest < Test::Unit::TestCase
end
assert_equal({:controller => 'pages', :action => 'show', :name => 'JAMIS'}, set.recognize_path('/page/JAMIS'))
end
def test_routes_with_symbols
set.draw do |map|
map.connect 'unnamed', :controller => :pages, :action => :show, :name => :as_symbol
map.named 'named', :controller => :pages, :action => :show, :name => :as_symbol
end
assert_equal({:controller => 'pages', :action => 'show', :name => :as_symbol}, set.recognize_path('/unnamed'))
assert_equal({:controller => 'pages', :action => 'show', :name => :as_symbol}, set.recognize_path('/named'))
end
end
class RouteLoadingTest < Test::Unit::TestCase