From 7501451d7f417a304a56ac65f0b203c942920732 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 12 Jan 2008 03:09:39 +0000 Subject: [PATCH] don't misbehave when redirecting to nil. Closes #10272 [farleyknight] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8633 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/base.rb | 3 ++- actionpack/test/controller/redirect_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index d419a09ec5..b0f713b049 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1029,7 +1029,8 @@ module ActionController #:nodoc: # RedirectBackError will be raised. You may specify some fallback # behavior for this case by rescuing RedirectBackError. def redirect_to(options = {}, response_status = {}) #:doc: - + raise ActionControllerError.new("Cannot redirect to nil!") if options.nil? + if options.is_a?(Hash) && options[:status] status = options.delete(:status) elsif response_status[:status] diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 5642792ca2..571d5b1f5a 100755 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -77,6 +77,10 @@ class RedirectController < ActionController::Base redirect_to Workshop.new(5, true) end + def redirect_to_nil + redirect_to nil + end + def rescue_errors(e) raise e end def rescue_action(e) raise end @@ -215,6 +219,13 @@ class RedirectTest < Test::Unit::TestCase get :redirect_to_new_record assert_equal "http://test.host/workshops", redirect_to_url end + + def test_redirect_to_nil + assert_raises(ActionController::ActionControllerError) do + get :redirect_to_nil + end + end + end module ModuleTest