diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index bdae5f9d869ba6d42e6d97fb566d9024c4cce509..106d9605af98cc82dc7072f879cdcb76b322d6c1 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -20,6 +20,7 @@ def define_dispatcher_callbacks(cache_classes) end if defined?(ActiveRecord) + after_dispatch :checkin_connections before_dispatch { ActiveRecord::Base.verify_active_connections! } to_prepare(:activerecord_instantiate_observers) { ActiveRecord::Base.instantiate_observers } end @@ -145,6 +146,21 @@ def flush_logger Base.logger.flush end + def mark_as_test_request! + @test_request = true + self + end + + def test_request? + @test_request + end + + def checkin_connections + # Don't return connection (and peform implicit rollback) if this request is a part of integration test + return if test_request? + ActiveRecord::Base.clear_active_connections! + end + protected def handle_request @controller = Routing::Routes.recognize(@request) diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index a98c1af7f900a48e8921af14a84c2f37c8c22656..fc473c269c5a25a2c1d3c7bb9d1bc35b066510d3 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -276,7 +276,7 @@ def process(method, path, parameters = nil, headers = nil) ActionController::Base.clear_last_instantiation! env['rack.input'] = data.is_a?(IO) ? data : StringIO.new(data || '') - @status, @headers, result_body = ActionController::Dispatcher.new.call(env) + @status, @headers, result_body = ActionController::Dispatcher.new.mark_as_test_request!.call(env) @request_count += 1 @controller = ActionController::Base.last_instantiation