Skip to content

Commit

Permalink
clearing active connections in the ConnectionManagement middleware if…
Browse files Browse the repository at this point in the history
… an exception happens
  • Loading branch information
tenderlove committed Mar 29, 2011
1 parent e524609 commit 3b2a032
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/connection_management_test.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 3b2a032

Please sign in to comment.