Permalink
Browse files

Clean up callbacks should also be called on exceptions.

  • Loading branch information...
1 parent df3cfa6 commit 819b8cae40623d26ce3c050d482b490539a25b98 @josevalim josevalim committed Dec 23, 2010
Showing with 17 additions and 0 deletions.
  1. +3 −0 actionpack/lib/action_dispatch/middleware/reloader.rb
  2. +14 −0 actionpack/test/dispatch/reloader_test.rb
@@ -68,6 +68,9 @@ def call(env)
response = @app.call(env)
response[2].extend(CleanupOnClose)
response
+ rescue Exception
+ _run_cleanup_callbacks
+ raise
end
end
end
@@ -116,6 +116,20 @@ def test_manual_reloading
assert cleaned
end
+ def test_cleanup_callbacks_are_called_on_exceptions
+ cleaned = false
+ Reloader.to_cleanup { cleaned = true }
+
+ begin
+ call_and_return_body do
+ raise "error"
+ end
+ rescue
+ end
+
+ assert cleaned
+ end
+
private
def call_and_return_body(&block)
@reloader ||= Reloader.new(block || proc {[200, {}, 'response']})

0 comments on commit 819b8ca

Please sign in to comment.