diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2012-01-16 14:36:41 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2012-01-16 14:36:41 +0300 |
commit | 2b812408c9f26468b392c81b4752e43ba3329bbc (patch) | |
tree | 2162376a2598116e5de8d1e51a88c20380337d0f /activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | |
parent | 3ded9b3c26e7fc2684ba1200ae9263d821408545 (diff) | |
download | rails-2b812408c9f26468b392c81b4752e43ba3329bbc.tar.gz rails-2b812408c9f26468b392c81b4752e43ba3329bbc.tar.bz2 rails-2b812408c9f26468b392c81b4752e43ba3329bbc.zip |
use Rack::BodyProxy in activerecord middlewares
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | 36 |
1 files changed, 5 insertions, 31 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 b8f99adc22..d69f02d504 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -406,35 +406,6 @@ module ActiveRecord end class ConnectionManagement - class Proxy # :nodoc: - attr_reader :body, :testing - - def initialize(body, testing = false) - @body = body - @testing = testing - end - - def method_missing(method_sym, *arguments, &block) - @body.send(method_sym, *arguments, &block) - end - - def respond_to?(method_sym, include_private = false) - super || @body.respond_to?(method_sym) - 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 @@ -442,9 +413,12 @@ module ActiveRecord def call(env) testing = env.key?('rack.test') - status, headers, body = @app.call(env) + response = @app.call(env) + response[2] = ::Rack::BodyProxy.new(response[2]) do + ActiveRecord::Base.clear_active_connections! unless testing + end - [status, headers, Proxy.new(body, testing)] + response rescue ActiveRecord::Base.clear_active_connections! unless testing raise |