1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Dont cache the conn_spec_name when empty

We cannot cache the connection_specification_name when it doesnt
exist. Thats because the parent value could change, and we should keep
failling back to the parent. If we cache that in a children as an ivar,
we would not fallback anymore in the next call, so the children would
not get the new parent spec_name.
This commit is contained in:
Arthur Neves 2016-05-11 08:04:26 -04:00
parent 525fa7ef7c
commit f1030fd897
No known key found for this signature in database
GPG key ID: 04A390FB1E433E17
2 changed files with 11 additions and 2 deletions

View file

@ -96,7 +96,7 @@ module ActiveRecord
# 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

View file

@ -91,7 +91,7 @@ module ActiveRecord
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 @@ module ActiveRecord
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