Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Routing: fix that route shorthand shouldn't ignore other options. Rai…

…se if :as option is given to root method since its name is always 'root'
  • Loading branch information...
commit 4d3602a8c4b38052c70655cd7d9dea42ae10ea8d 1 parent 1ee50e5
Jeremy Kemper jeremy authored
6 actionpack/lib/action_dispatch/routing/mapper.rb
View
@@ -35,13 +35,15 @@ def initialize(set)
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)
end
def match(*args)
if args.one? && args.first.is_a?(Hash)
- path = args.first.keys.first
- options = { :to => args.first.values.first }
+ options = args.first
+ path = options.keys.first
+ options[:to] = options.delete(path)
else
path = args.first
options = args.extract_options!
6 actionpack/test/dispatch/routing_test.rb
View
@@ -22,7 +22,7 @@ def self.matches?(request)
delete 'logout', :to => :destroy, :as => :logout
end
- match 'account/logout' => redirect("/logout")
+ match 'account/logout' => redirect("/logout"), :as => :logout_redirect
match 'account/login', :to => redirect("/login")
match 'account/modulo/:name', :to => redirect("/%{name}s")
@@ -109,7 +109,7 @@ def self.matches?(request)
scope ':access_token', :constraints => { :access_token => /\w{5,5}/ } do
resources :rooms
end
-
+
root :to => 'projects#index'
end
end
@@ -153,6 +153,7 @@ def test_login_redirect
def test_logout_redirect_without_to
with_test_routes do
+ assert_equal '/account/logout', logout_redirect_path
get '/account/logout'
assert_equal 301, @response.status
assert_equal 'http://www.example.com/logout', @response.headers['Location']
@@ -462,6 +463,7 @@ def test_access_token_rooms
def test_root
with_test_routes do
+ assert_equal '/', root_path
get '/'
assert_equal 'projects#index', @response.body
end

1 comment on commit 4d3602a

Sam Ruby

Unfortunately:

match '/admin/logout' => 'store#logout', :as => 'logout'

gets processed as

match 'as', :to => 'logout'

I also feel that prohibiting root :as is unnecessary, when a simple reverse_merge would allow it.

Please sign in to comment.
Something went wrong with that request. Please try again.