aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorArthur Nogueira Neves <github@arthurnn.com>2016-05-11 09:02:10 -0400
committerArthur Nogueira Neves <github@arthurnn.com>2016-05-11 09:02:10 -0400
commit733161d48b4292c8731c35eaa20131a49c5a5b9a (patch)
tree5b3339fe050241eedf4cecaa17c09980ddde8f52 /activerecord
parent897decaceb0e48669391af7e20b7b7aff848e6d7 (diff)
parentf1030fd897640f2d051ee29143544fad5b64d6d3 (diff)
downloadrails-733161d48b4292c8731c35eaa20131a49c5a5b9a.tar.gz
rails-733161d48b4292c8731c35eaa20131a49c5a5b9a.tar.bz2
rails-733161d48b4292c8731c35eaa20131a49c5a5b9a.zip
Merge pull request #24971 from arthurnn/arthurnn/dont_cache_specification_name
Dont cache the conn_spec_name when empty
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_handling.rb2
-rw-r--r--activerecord/test/cases/connection_adapters/connection_handler_test.rb11
2 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index 74bbf6fc36..25306d6945 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -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
diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
index 62beb8bea4..2d3c411479 100644
--- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb
+++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb
@@ -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