aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSimon Eskildsen <sirup@sirupsen.com>2014-09-23 02:26:54 +0000
committerSimon Eskildsen <sirup@sirupsen.com>2014-09-23 02:33:18 +0000
commitcb598c211579a4a763f2ad2376bc99f85a44dd13 (patch)
treea57f92e469f1085b351d31f311b36a2b6ba3dc63 /activerecord
parentfc6accfa9ad8f2a9871c574a6d739388eea2a8f9 (diff)
downloadrails-cb598c211579a4a763f2ad2376bc99f85a44dd13.tar.gz
rails-cb598c211579a4a763f2ad2376bc99f85a44dd13.tar.bz2
rails-cb598c211579a4a763f2ad2376bc99f85a44dd13.zip
ar/connection_pool: honor overriden rack.test in middleware
Honoring an overidden `rack.test` allows testing closed connection between multiple requests. This is useful if you're working on database resiliency, to ensure the connection is in the expected state from one request to another on the same worker.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb2
-rw-r--r--activerecord/test/cases/connection_management_test.rb8
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)