aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-04-04 13:00:22 -0700
committerwycats <wycats@gmail.com>2010-04-04 13:17:14 -0700
commitb546945b51d1e5765b4bf4eba0bd8413ea8e4198 (patch)
treeb559e3f02b41c622be48b6af8801577ffaaa2e93
parent50cdb654ac4ff1bde2f432d205932a6887f6f92f (diff)
downloadrails-b546945b51d1e5765b4bf4eba0bd8413ea8e4198.tar.gz
rails-b546945b51d1e5765b4bf4eba0bd8413ea8e4198.tar.bz2
rails-b546945b51d1e5765b4bf4eba0bd8413ea8e4198.zip
Reapply redirect {|params, request| } with passing tests this time
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb6
-rw-r--r--actionpack/test/dispatch/routing_test.rb11
2 files changed, 16 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index ffa178345b..925e91f081 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -243,7 +243,11 @@ module ActionDispatch
lambda do |env|
req = Request.new(env)
- uri = URI.parse(path_proc.call(req.symbolized_path_parameters))
+
+ params = [req.symbolized_path_parameters]
+ params << req if path_proc.arity > 1
+
+ uri = URI.parse(path_proc.call(*params))
uri.scheme ||= req.scheme
uri.host ||= req.host
uri.port ||= req.port unless req.port == 80
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index bb7c322790..6ff478aec1 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -39,6 +39,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
match 'account/modulo/:name', :to => redirect("/%{name}s")
match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" }
+ match 'account/proc_req' => redirect {|params, req| "/#{req.method}" }
+
match 'account/google' => redirect('http://www.google.com/')
match 'openid/login', :via => [:get, :post], :to => "openid#login"
@@ -351,6 +353,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_redirect_proc_with_request
+ with_test_routes do
+ get '/account/proc_req'
+ assert_equal 301, @response.status
+ assert_equal 'http://www.example.com/GET', @response.headers['Location']
+ assert_equal 'Moved Permanently', @response.body
+ end
+ end
+
def test_openid
with_test_routes do
get '/openid/login'