Ensure ActiveRecord::ConnectionPool.connected? handles undefined connections. [#936 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
Wes Oldenbeuving
2008-11-05 18:27:23 +01:00
committed by Pratik Naik
parent 5fad229e43
commit 32089cbcc9
2 changed files with 9 additions and 1 deletions

View File

@@ -324,7 +324,7 @@ module ActiveRecord
# Returns true if a connection that's accessible to this class has
# already been opened.
def connected?(klass)
retrieve_connection_pool(klass).connected?
conn = retrieve_connection_pool(klass) ? conn.connected? : false
end
# Remove the connection for this class. This will close the active

View File

@@ -73,6 +73,14 @@ class PooledConnectionsTest < ActiveRecord::TestCase
assert ActiveRecord::ConnectionAdapters::AbstractAdapter === conn
conn_pool.checkin(conn)
end
def test_undefined_connection_returns_false
old_handler = ActiveRecord::Base.connection_handler
ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
assert_equal false, ActiveRecord::Base.connected?
ensure
ActiveRecord::Base.connection_handler = old_handler
end
end unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name
class AllowConcurrencyDeprecatedTest < ActiveRecord::TestCase