diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-09-23 07:54:03 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-09-23 07:54:03 -0700 |
commit | 4e8ea13ba1a0870905a46fac5f232d9f41eef8a4 (patch) | |
tree | b2c8a06f89bddb632526dc68139f3df21fd7d8bf /activerecord | |
parent | f8b44d1d33dd3a9795e77153eb4cb5461c43d624 (diff) | |
parent | cb598c211579a4a763f2ad2376bc99f85a44dd13 (diff) | |
download | rails-4e8ea13ba1a0870905a46fac5f232d9f41eef8a4.tar.gz rails-4e8ea13ba1a0870905a46fac5f232d9f41eef8a4.tar.bz2 rails-4e8ea13ba1a0870905a46fac5f232d9f41eef8a4.zip |
Merge pull request #17020 from Sirupsen/ar-override-rack-test
activerecord/connection_pool: honor overidden rack.test in tests
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/connection_management_test.rb | 8 |
3 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f195b73437..147599d5c3 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Honor overridden `rack.test` in Rack environment for the connection + management middlware. + + *Simon Eskildsen* + * Add a truncate method to the connection. *Aaron Patterson* 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 bc1a670b42..9760729da3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -640,7 +640,7 @@ module ActiveRecord end def call(env) - testing = env.key?('rack.test') + testing = env['rack.test'] response = @app.call(env) response[2] = ::Rack::BodyProxy.new(response[2]) do diff --git a/activerecord/test/cases/connection_management_test.rb b/activerecord/test/cases/connection_management_test.rb index 77d9ae9b8e..f53c496ecd 100644 --- a/activerecord/test/cases/connection_management_test.rb +++ b/activerecord/test/cases/connection_management_test.rb @@ -96,6 +96,14 @@ module ActiveRecord assert ActiveRecord::Base.connection_handler.active_connections? end + def test_connections_closed_if_exception_and_explicitly_not_test + @env['rack.test'] = false + app = Class.new(App) { def call(env); raise NotImplementedError; end }.new + explosive = ConnectionManagement.new(app) + assert_raises(NotImplementedError) { 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) |