Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make sure that active connections are not cleared during test when an…

… exception happens
  • Loading branch information...
commit c7b7c6ad1c773102753f1a11b857d0e37ceb6a21 1 parent 3b2a032
Aaron Patterson tenderlove authored
6 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
View
@@ -443,11 +443,13 @@ def initialize(app)
end
def call(env)
+ testing = env.key?('rack.test')
+
status, headers, body = @app.call(env)
- [status, headers, Proxy.new(body, env.key?('rack.test'))]
+ [status, headers, Proxy.new(body, testing)]
rescue
- ActiveRecord::Base.clear_active_connections!
+ ActiveRecord::Base.clear_active_connections! unless testing
raise
end
end
8 activerecord/test/cases/connection_management_test.rb
View
@@ -64,6 +64,14 @@ def test_connections_closed_if_exception
assert !ActiveRecord::Base.connection_handler.active_connections?
end
+ def test_connections_not_closed_if_exception_and_test
+ @env['rack.test'] = true
+ 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)

2 comments on commit c7b7c6a

Simon Eskildsen

Can you explain why this was needed? I can't come up with a good reason.

Simon Eskildsen

Ah, because of transactional fixtures. I get it

Please sign in to comment.
Something went wrong with that request. Please try again.