Permalink
Browse files

clearing active connections in the ConnectionManagement middleware if…

… an exception happens
  • Loading branch information...
1 parent e524609 commit 3b2a032677a2261499aa5d2de019f31f1173a858 @tenderlove tenderlove committed Mar 29, 2011
@@ -446,6 +446,9 @@ def call(env)
status, headers, body = @app.call(env)
[status, headers, Proxy.new(body, env.key?('rack.test'))]
+ rescue
+ ActiveRecord::Base.clear_active_connections!
+ raise
end
end
end
@@ -57,6 +57,13 @@ def test_active_connections_are_not_cleared_on_body_close_during_test
assert ActiveRecord::Base.connection_handler.active_connections?
end
+ def test_connections_closed_if_exception
+ app = Class.new(App) { def call(env); raise; end }.new
+ explosive = ConnectionManagement.new(app)
+ assert_raises(RuntimeError) { explosive.call(@env) }
+ assert !ActiveRecord::Base.connection_handler.active_connections?
+ end
+
test "doesn't clear active connections when running in a test case" do
@env['rack.test'] = true
@management.call(@env)

0 comments on commit 3b2a032

Please sign in to comment.