class ActiveRecord::ConnectionAdapters::ConnectionManagementTest
Public Instance Methods
call(env)
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 62 def call(env); raise NotImplementedError; end
setup()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 23 def setup @env = {} @app = App.new @management = middleware(@app) # make sure we have an active connection assert ActiveRecord::Base.connection assert ActiveRecord::Base.connection_handler.active_connections? end
test_active_connections_are_not_cleared_on_body_close_during_transaction()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 53 def test_active_connections_are_not_cleared_on_body_close_during_transaction ActiveRecord::Base.transaction do _, _, body = @management.call(@env) body.close assert ActiveRecord::Base.connection_handler.active_connections? end end
test_app_delegation()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 33 def test_app_delegation manager = middleware(@app) manager.call @env assert_equal [@env], @app.calls end
test_body_responds_to_each()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 40 def test_body_responds_to_each _, _, body = @management.call(@env) bits = [] body.each { |bit| bits << bit } assert_equal ["hi mom"], bits end
test_connections_are_cleared_after_body_close()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 47 def test_connections_are_cleared_after_body_close _, _, body = @management.call(@env) body.close assert !ActiveRecord::Base.connection_handler.active_connections? end
test_connections_closed_if_exception()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 61 def test_connections_closed_if_exception app = Class.new(App) { def call(env); raise NotImplementedError; end }.new explosive = middleware(app) assert_raises(NotImplementedError) { explosive.call(@env) } assert !ActiveRecord::Base.connection_handler.active_connections? end
test_connections_not_closed_if_exception_inside_transaction()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 68 def test_connections_not_closed_if_exception_inside_transaction ActiveRecord::Base.transaction do app = Class.new(App) { def call(env); raise RuntimeError; end }.new explosive = middleware(app) assert_raises(RuntimeError) { explosive.call(@env) } assert ActiveRecord::Base.connection_handler.active_connections? end end
to_path()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 85 def to_path; "/path"; end
Private Instance Methods
executor()
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 100 def executor @executor ||= Class.new(ActiveSupport::Executor).tap do |exe| ActiveRecord::QueryCache.install_executor_hooks(exe) end end
middleware(app)
click to toggle source
# File activerecord/test/cases/connection_management_test.rb, line 106 def middleware(app) lambda do |env| a, b, c = executor.wrap { app.call(env) } [a, b, Rack::BodyProxy.new(c) {}] end end