提交 733161d4 编写于 作者: A Arthur Nogueira Neves

Merge pull request #24971 from arthurnn/arthurnn/dont_cache_specification_name

Dont cache the conn_spec_name when empty
......@@ -96,7 +96,7 @@ def connection
# Return the specification name from the current class or its parent.
def connection_specification_name
if !defined?(@connection_specification_name) || @connection_specification_name.nil?
@connection_specification_name = self == Base ? "primary" : superclass.connection_specification_name
return self == Base ? "primary" : superclass.connection_specification_name
end
@connection_specification_name
end
......
......@@ -91,7 +91,7 @@ def test_retrieve_connection_pool_copies_schema_cache_from_ancestor_pool
end
def test_a_class_using_custom_pool_and_switching_back_to_primary
klass2 = Class.new(Base) { def self.name; 'klass2'; end }
klass2 = Class.new(Base) { def self.name; 'klass2'; end }
assert_equal klass2.connection.object_id, ActiveRecord::Base.connection.object_id
......@@ -103,6 +103,15 @@ def test_a_class_using_custom_pool_and_switching_back_to_primary
assert_equal klass2.connection.object_id, ActiveRecord::Base.connection.object_id
end
def test_connection_specification_name_should_fallback_to_parent
klassA = Class.new(Base)
klassB = Class.new(klassA)
assert_equal klassB.connection_specification_name, klassA.connection_specification_name
klassA.connection_specification_name = "readonly"
assert_equal "readonly", klassB.connection_specification_name
end
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册