diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-29 15:37:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-29 15:37:07 -0700 |
commit | e5246092d1ce30961af4f7d9b5ad86071298cf1c (patch) | |
tree | 8293f01bc0b6858410167c3722ecdc58acf881c3 /activerecord/lib | |
parent | 94907035b6a4a8e415cf19471a7ae77fac937209 (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 31 |
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 |