diff options
-rw-r--r-- | actionpack/lib/action_controller/filters.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/filters_test.rb | 35 |
2 files changed, 40 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb index 58f0ca491d..5705960eb5 100644 --- a/actionpack/lib/action_controller/filters.rb +++ b/actionpack/lib/action_controller/filters.rb @@ -713,6 +713,11 @@ module ActionController #:nodoc: perform_action_without_filters unless performed? || aborted return index if aborted || nesting != 0 + # if an around filter catches an exception during rendering and handles it, e.g. + # by rendering an error page, we might have left over around filters in the filter + # chain. so skip over these. + index = index.next while (filter = chain[index]) && filter.type == :around + # run after filters, if any while chain[index] filter, index = skip_excluded_filters(chain, index) diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index e84661b688..a38e55fb52 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -324,6 +324,31 @@ class FilterTest < Test::Unit::TestCase render :text => 'hello' end end + + class ErrorToRescue < Exception; end + + class RescuingAroundFilterWithBlock + def filter(controller) + begin + yield + rescue ErrorToRescue => ex + controller.send :render, :text => "I rescued this: #{ex.inspect}" + end + end + end + + class RescuedController < ActionController::Base + around_filter RescuingAroundFilterWithBlock.new + + def show + raise ErrorToRescue.new("Something made the bad noise.") + end + + private + def rescue_action(exception) + raise exception + end + end def test_empty_filter_chain assert_equal 0, EmptyFilterChainController.filter_chain.size @@ -491,6 +516,16 @@ class FilterTest < Test::Unit::TestCase def test_changing_the_requirements assert_equal nil, test_process(ChangingTheRequirementsController, "go_wild").template.assigns['ran_filter'] end + + def test_a_rescuing_around_filter + response = nil + assert_nothing_raised do + response = test_process(RescuedController) + end + + assert response.success? + assert_equal("I rescued this: #<FilterTest::ErrorToRescue: Something made the bad noise.>", response.body) + end private def test_process(controller, action = "show") |