Skip to content

Commit

Permalink
Update test to use a class with a real constant name
Browse files Browse the repository at this point in the history
Otherwise PoolConfig fails to constantize "klass2". I don't think we
care if we support classes that don't have real names.
  • Loading branch information
flavorjones committed Jan 24, 2025
1 parent c883a3f commit 1bf2c84
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,19 @@ def test_connection_pools
assert_equal([@pool], @handler.connection_pools)
end

def test_a_class_using_custom_pool_and_switching_back_to_primary
klass2 = Class.new(Base) { def self.name; "klass2"; end }
class MyClass2 < Base
end

assert_same klass2.lease_connection, ActiveRecord::Base.lease_connection
def test_a_class_using_custom_pool_and_switching_back_to_primary
assert_same MyClass2.lease_connection, ActiveRecord::Base.lease_connection

pool = klass2.establish_connection(ActiveRecord::Base.connection_pool.db_config.configuration_hash)
assert_same klass2.lease_connection, pool.lease_connection
assert_not_same klass2.lease_connection, ActiveRecord::Base.lease_connection
pool = MyClass2.establish_connection(ActiveRecord::Base.connection_pool.db_config.configuration_hash)
assert_same MyClass2.lease_connection, pool.lease_connection
assert_not_same MyClass2.lease_connection, ActiveRecord::Base.lease_connection

klass2.remove_connection
MyClass2.remove_connection

assert_same klass2.lease_connection, ActiveRecord::Base.lease_connection
assert_same MyClass2.lease_connection, ActiveRecord::Base.lease_connection
end

class ApplicationRecord < ActiveRecord::Base
Expand Down

0 comments on commit 1bf2c84

Please sign in to comment.