Permalink
Browse files

Demonstrates a routing bug.

When you call 'request.params' in a constraint matcher, subsequent
routes don't have their path attributes set correctly.

In this case, a URL of '/about' would have params[:something] == 'about' in the route
  match ':id'

Adding this constraint and route causes the following test to fail.

  1) Failure:
test_default_params(TestRoutingMapper)
[/Users/joevandyk/projects/rails/actionpack/test/dispatch/routing_test.rb:1475]:
<"home"> expected but was
<nil>.
  • Loading branch information...
Joe Van Dyk authored and franckverrot committed Aug 12, 2011
1 parent 99f87c9 commit 6eab906cfa68de53e1866f9cb8b3c16d22a78d34
Showing with 9 additions and 0 deletions.
  1. +9 −0 actionpack/test/dispatch/routing_test.rb
@@ -14,6 +14,13 @@ def self.matches?(request)
end
end
+ class RequestLookup
+ def self.matches?(request)
+ request.params
+ return false
+ end
+ end
+
class YoutubeFavoritesRedirector
def self.call(params, request)
"http://www.youtube.com/watch?v=#{params[:youtube_id]}"
@@ -26,6 +33,8 @@ def self.call(params, request)
default_url_options :host => "rubyonrails.org"
resources_path_names :correlation_indexes => "info_about_correlation_indexes"
+ match ':something' => 'foo#something', :constraints => RequestLookup
+
controller :sessions do
get 'login' => :new
post 'login' => :create

0 comments on commit 6eab906

Please sign in to comment.