Skip to content

Commit

Permalink
Reapply redirect {|params, request| } with passing tests this time
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Apr 4, 2010
1 parent 50cdb65 commit b546945
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -243,7 +243,11 @@ def redirect(*args, &block)

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
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Expand Up @@ -39,6 +39,8 @@ def self.matches?(request)

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"
Expand Down Expand Up @@ -351,6 +353,15 @@ def test_redirect_proc
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'
Expand Down

0 comments on commit b546945

Please sign in to comment.