aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-29 15:37:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-29 15:37:07 -0700
commite5246092d1ce30961af4f7d9b5ad86071298cf1c (patch)
tree8293f01bc0b6858410167c3722ecdc58acf881c3 /activerecord/lib/active_record/connection_adapters/abstract
parent94907035b6a4a8e415cf19471a7ae77fac937209 (diff)
downloadrails-e5246092d1ce30961af4f7d9b5ad86071298cf1c.tar.gz
rails-e5246092d1ce30961af4f7d9b5ad86071298cf1c.tar.bz2
rails-e5246092d1ce30961af4f7d9b5ad86071298cf1c.zip
proxy body responses so we close database connections after body is flushed
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb31
1 files changed, 24 insertions, 7 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 7a900055a9..5e12f80263 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -417,18 +417,35 @@ module ActiveRecord
end
class ConnectionManagement
+ class Proxy # :nodoc:
+ attr_reader :body, :testing
+
+ def initialize(body, testing = false)
+ @body = body
+ @testing = testing
+ end
+
+ def each(&block)
+ body.each(&block)
+ end
+
+ def close
+ body.close if body.respond_to?(:close)
+
+ # Don't return connection (and perform implicit rollback) if
+ # this request is a part of integration test
+ ActiveRecord::Base.clear_active_connections! unless testing
+ end
+ end
+
def initialize(app)
@app = app
end
def call(env)
- @app.call(env)
- ensure
- # Don't return connection (and perform implicit rollback) if
- # this request is a part of integration test
- unless env.key?("rack.test")
- ActiveRecord::Base.clear_active_connections!
- end
+ status, headers, body = @app.call(env)
+
+ [status, headers, Proxy.new(body, env.key?('rack.test'))]
end
end
end