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

Changeset 6810

Show
Ignore:
Timestamp:
05/22/07 19:17:43 (1 year ago)
Author:
xal
Message:

Rescuing in around_filters works as expected again [codahale, Stephan Kaes]. Closes #8341

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/filters.rb

    r6670 r6810  
    714714        return index if aborted || nesting != 0 
    715715 
     716        # if an around filter catches an exception during rendering and handles it, e.g. 
     717        # by rendering an error page, we might have left over around filters in the filter 
     718        # chain. so skip over these. 
     719        index = index.next while (filter = chain[index]) && filter.type == :around 
     720 
    716721        # run after filters, if any 
    717722        while chain[index] 
  • trunk/actionpack/test/controller/filters_test.rb

    r6669 r6810  
    323323    def show 
    324324      render :text => 'hello' 
     325    end 
     326  end 
     327   
     328  class ErrorToRescue < Exception; end 
     329   
     330  class RescuingAroundFilterWithBlock 
     331    def filter(controller) 
     332      begin 
     333        yield 
     334      rescue ErrorToRescue => ex 
     335        controller.send :render, :text => "I rescued this: #{ex.inspect}" 
     336      end 
     337    end 
     338  end 
     339   
     340  class RescuedController < ActionController::Base 
     341    around_filter RescuingAroundFilterWithBlock.new 
     342     
     343    def show 
     344      raise ErrorToRescue.new("Something made the bad noise.") 
     345    end 
     346     
     347  private 
     348    def rescue_action(exception) 
     349      raise exception 
    325350    end 
    326351  end 
     
    491516  def test_changing_the_requirements 
    492517    assert_equal nil, test_process(ChangingTheRequirementsController, "go_wild").template.assigns['ran_filter'] 
     518  end 
     519   
     520  def test_a_rescuing_around_filter 
     521    response = nil 
     522    assert_nothing_raised do 
     523      response = test_process(RescuedController) 
     524    end 
     525     
     526    assert response.success? 
     527    assert_equal("I rescued this: #<FilterTest::ErrorToRescue: Something made the bad noise.>", response.body) 
    493528  end 
    494529