Permalink
Browse files

Fix the redirect when it receive blocks with arity of 1.

Closes #5677
  • Loading branch information...
1 parent 9894d16 commit 27fc6ec95eb7a1756fb86693b6fe8e03f1d66ef3 @rafaelfranca rafaelfranca committed with drogus Mar 31, 2012
Showing with 17 additions and 1 deletion.
  1. +2 −1 actionpack/lib/action_dispatch/routing/redirection.rb
  2. +15 −0 actionpack/test/dispatch/routing_test.rb
@@ -102,7 +102,8 @@ def redirect(*args, &block)
if block && block.respond_to?(:arity) && block.arity < 2
msg = "redirect blocks with arity of #{block.arity} are deprecated. Your block must take 2 parameters: the environment, and a request object"
ActiveSupport::Deprecation.warn msg
- block = lambda { |params, _| block.call(params) }
+ deprecated_block = block
+ block = lambda { |params, _| deprecated_block.call(params) }
end
raise ArgumentError, "redirection argument not supported" unless block
@@ -694,6 +694,21 @@ def test_redirect_modulo
def test_redirect_proc
with_test_routes do
get '/account/proc/person'
+
+ verify_redirect 'http://www.example.com/people'
+ end
+ end
+
+ def test_redirect_deprecated_proc
+ assert_deprecated do
+ self.class.stub_controllers do |routes|
+ routes.draw { match 'account/deprecated_proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" } }
+ end
+ end
+
+ with_test_routes do
+ get '/account/proc/person'
+
verify_redirect 'http://www.example.com/people'
end
end

0 comments on commit 27fc6ec

Please sign in to comment.