aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-12-23 19:17:02 +0100
committerJosé Valim <jose.valim@gmail.com>2010-12-23 19:17:02 +0100
commit819b8cae40623d26ce3c050d482b490539a25b98 (patch)
tree44d62b397d7eac18be664f24b0b8aeff53535876 /actionpack
parentdf3cfa6aaea326bb60b639524abbcc1f73854d1f (diff)
downloadrails-819b8cae40623d26ce3c050d482b490539a25b98.tar.gz
rails-819b8cae40623d26ce3c050d482b490539a25b98.tar.bz2
rails-819b8cae40623d26ce3c050d482b490539a25b98.zip
Clean up callbacks should also be called on exceptions.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/middleware/reloader.rb3
-rw-r--r--actionpack/test/dispatch/reloader_test.rb14
2 files changed, 17 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/reloader.rb b/actionpack/lib/action_dispatch/middleware/reloader.rb
index 7624a1871a..f6ab368ad8 100644
--- a/actionpack/lib/action_dispatch/middleware/reloader.rb
+++ b/actionpack/lib/action_dispatch/middleware/reloader.rb
@@ -68,6 +68,9 @@ module ActionDispatch
response = @app.call(env)
response[2].extend(CleanupOnClose)
response
+ rescue Exception
+ _run_cleanup_callbacks
+ raise
end
end
end
diff --git a/actionpack/test/dispatch/reloader_test.rb b/actionpack/test/dispatch/reloader_test.rb
index 995b19030c..eaabc1feb3 100644
--- a/actionpack/test/dispatch/reloader_test.rb
+++ b/actionpack/test/dispatch/reloader_test.rb
@@ -116,6 +116,20 @@ class ReloaderTest < Test::Unit::TestCase
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']})