Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10272: redirect_to_nil_raises_its_own_exception.diff

File redirect_to_nil_raises_its_own_exception.diff, 1.6 kB (added by farleyknight, 6 months ago)

Simple patch which raises RedirectToNil instead of SystemStackError (update for Edge Rails)

  • actionpack/test/controller/redirect_test.rb

    old new  
    7777    redirect_to Workshop.new(5, true) 
    7878  end 
    7979 
     80  def redirect_to_nil 
     81    redirect_to nil 
     82  end 
     83 
    8084  def rescue_errors(e) raise e end 
    8185     
    8286  def rescue_action(e) raise end 
     
    215219    get :redirect_to_new_record 
    216220    assert_equal "http://test.host/workshops", redirect_to_url 
    217221  end 
     222 
     223  def test_redirect_to_nil 
     224    assert_raises(ActionController::RedirectToNil) do 
     225      get :redirect_to_nil 
     226    end 
     227  end 
     228 
    218229end 
    219230 
    220231module ModuleTest 
  • actionpack/lib/action_controller/base.rb

    old new  
    2121  class RenderError < ActionControllerError #:nodoc: 
    2222  end 
    2323 
     24  class RedirectToNil < ActionControllerError #:nodoc: 
     25  end 
     26 
    2427  class RoutingError < ActionControllerError #:nodoc: 
    2528    attr_reader :failures 
    2629    def initialize(message, failures=[]) 
     
    10291032      # RedirectBackError will be raised. You may specify some fallback 
    10301033      # behavior for this case by rescuing RedirectBackError. 
    10311034      def redirect_to(options = {}, response_status = {}) #:doc:  
    1032          
     1035        raise RedirectToNil.new("Cannot redirect to nil!") if options.nil?  
     1036 
    10331037        if options.is_a?(Hash) && options[:status]  
    10341038          status = options.delete(:status)  
    10351039        elsif response_status[:status]