aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-29 15:47:16 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-29 15:47:16 -0700
commitc7b7c6ad1c773102753f1a11b857d0e37ceb6a21 (patch)
treed9caf7c3e9a7b1c114f6f50127dfd3ad920843cc /activerecord
parent3b2a032677a2261499aa5d2de019f31f1173a858 (diff)
downloadrails-c7b7c6ad1c773102753f1a11b857d0e37ceb6a21.tar.gz
rails-c7b7c6ad1c773102753f1a11b857d0e37ceb6a21.tar.bz2
rails-c7b7c6ad1c773102753f1a11b857d0e37ceb6a21.zip
make sure that active connections are not cleared during test when an exception happens
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb6
-rw-r--r--activerecord/test/cases/connection_management_test.rb8
2 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 45900d27dc..b4db1eed18 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -443,11 +443,13 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/connection_management_test.rb b/activerecord/test/cases/connection_management_test.rb
index 0d4a9a287e..85871aebdf 100644
--- a/activerecord/test/cases/connection_management_test.rb
+++ b/activerecord/test/cases/connection_management_test.rb
@@ -64,6 +64,14 @@ module ActiveRecord
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)