Permalink
Browse files

Clean up Sweeper controller accessor when an Error is raised

  • Loading branch information...
1 parent e482100 commit 35fe3107a39271c9694e5094c1352c30463582e4 @f1sherman f1sherman committed Jul 19, 2012
Showing with 18 additions and 2 deletions.
  1. +7 −2 actionpack/lib/action_controller/caching/sweeping.rb
  2. +11 −0 actionpack/test/controller/filters_test.rb
@@ -68,14 +68,14 @@ def before(controller)
def after(controller)
self.controller = controller
callback(:after) if controller.perform_caching
- # Clean up, so that the controller can be collected after this request
- self.controller = nil
end
def around(controller)
before(controller)
yield
after(controller)
+ ensure
+ clean_up
end
protected
@@ -90,6 +90,11 @@ def assigns(key)
end
private
+ def clean_up
+ # Clean up, so that the controller can be collected after this request
+ self.controller = nil
+ end
+
def callback(timing)
controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"
@@ -505,6 +505,10 @@ class SweeperTestController < ActionController::Base
def show
render :text => 'hello world'
end
+
+ def error
+ raise StandardError.new
+ end
end
class ImplicitActionsController < ActionController::Base
@@ -534,6 +538,13 @@ def test_sweeper_should_not_block_rendering
assert_equal 'hello world', response.body
end
+ def test_sweeper_should_clean_up_if_exception_is_raised
+ assert_raise StandardError do
+ test_process(SweeperTestController, 'error')
+ end
+ assert_nil AppSweeper.instance.controller
+ end
+
def test_before_method_of_sweeper_should_always_return_true
sweeper = ActionController::Caching::Sweeper.send(:new)
assert sweeper.before(TestController.new)

0 comments on commit 35fe310

Please sign in to comment.