Skip to content
This repository
Browse code

Make sure ActiveRecord::Base.connected? doesn't raise an exception fo…

…r defined connections
  • Loading branch information...
commit 0832bc63f4047d0ad0171c411460db23450213aa 1 parent 396d599
Pratik authored November 06, 2008
3  activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -324,7 +324,8 @@ def retrieve_connection(klass) #:nodoc:
324 324
       # Returns true if a connection that's accessible to this class has
325 325
       # already been opened.
326 326
       def connected?(klass)
327  
-        conn = retrieve_connection_pool(klass) ? conn.connected? : false
  327
+        conn = retrieve_connection_pool(klass)
  328
+        conn ? conn.connected? : false
328 329
       end
329 330
 
330 331
       # Remove the connection for this class. This will close the active
5  activerecord/test/cases/pooled_connections_test.rb
@@ -74,6 +74,11 @@ def test_pooled_connection_checkout_existing_first
74 74
     conn_pool.checkin(conn)
75 75
   end
76 76
 
  77
+  def test_not_connected_defined_connection_reutnrs_false
  78
+    ActiveRecord::Base.establish_connection(@connection)
  79
+    assert ! ActiveRecord::Base.connected?
  80
+  end
  81
+
77 82
   def test_undefined_connection_returns_false
78 83
     old_handler = ActiveRecord::Base.connection_handler
79 84
     ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new

0 notes on commit 0832bc6

Please sign in to comment.
Something went wrong with that request. Please try again.