Skip to content

Commit

Permalink
Merge pull request #2897 from rsutphin/ar31-remove_connection
Browse files Browse the repository at this point in the history
Patch for issue #2820
  • Loading branch information
tenderlove committed Sep 7, 2011
2 parents 4263a79 + c5af3a6 commit 9198c7a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Expand Up @@ -421,7 +421,7 @@ def connected?(klass)
# can be used as an argument for establish_connection, for easily
# re-establishing the connection.
def remove_connection(klass)
pool = @connection_pools[klass.name]
pool = @connection_pools.delete(klass.name)
return nil unless pool

pool.automatic_reconnect = false
Expand Down
Expand Up @@ -100,7 +100,7 @@ def connection_config
end

def connection_pool
connection_handler.retrieve_connection_pool(self)
connection_handler.retrieve_connection_pool(self) or raise ConnectionNotEstablished
end

def retrieve_connection
Expand Down
Expand Up @@ -6,7 +6,12 @@ class ConnectionHandlerTest < ActiveRecord::TestCase
def setup
@handler = ConnectionHandler.new
@handler.establish_connection 'america', Base.connection_pool.spec
@klass = Struct.new(:name).new('america')
@klass = Class.new do
def self.name; 'america'; end
end
@subklass = Class.new(@klass) do
def self.name; 'north america'; end
end
end

def test_retrieve_connection
Expand All @@ -28,6 +33,20 @@ def test_retrieve_connection_pool_with_ar_base
def test_retrieve_connection_pool
assert_not_nil @handler.retrieve_connection_pool(@klass)
end

def test_retrieve_connection_pool_uses_superclass_when_no_subclass_connection
assert_not_nil @handler.retrieve_connection_pool(@subklass)
end

def test_retrieve_connection_pool_uses_superclass_pool_after_subclass_establish_and_remove
@handler.establish_connection 'north america', Base.connection_pool.spec
assert_not_same @handler.retrieve_connection_pool(@klass),
@handler.retrieve_connection_pool(@subklass)

@handler.remove_connection @subklass
assert_same @handler.retrieve_connection_pool(@klass),
@handler.retrieve_connection_pool(@subklass)
end
end
end
end

0 comments on commit 9198c7a

Please sign in to comment.