aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorArthur Neves <arthurnn@gmail.com>2016-06-14 12:31:08 -0400
committerArthur Neves <arthurnn@gmail.com>2016-06-14 12:37:50 -0400
commit009b2a54344eb2463fa4018d9b20cdfc4c0495ac (patch)
treec68c9d5ba83aee03675a564cbb2df572489a63ed /activerecord/test/cases
parent596669cfac8e63d14f905bc1a8891796d3c00b02 (diff)
downloadrails-009b2a54344eb2463fa4018d9b20cdfc4c0495ac.tar.gz
rails-009b2a54344eb2463fa4018d9b20cdfc4c0495ac.tar.bz2
rails-009b2a54344eb2463fa4018d9b20cdfc4c0495ac.zip
Respect the current `connected?` method when calling `cache`
Before we enable query caching we check if the connection is connected. Before this fix we were always checking against the main connection, and not the model connection.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/query_cache_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb
index 199a41d428..25b16ae142 100644
--- a/activerecord/test/cases/query_cache_test.rb
+++ b/activerecord/test/cases/query_cache_test.rb
@@ -174,6 +174,21 @@ class QueryCacheTest < ActiveRecord::TestCase
ActiveRecord::Base.configurations = conf
end
+ def test_cache_is_not_available_when_using_a_not_connected_connection
+ spec_name = Task.connection_specification_name
+ conf = ActiveRecord::Base.configurations['arunit'].merge('name' => 'test2')
+ ActiveRecord::Base.connection_handler.establish_connection(conf)
+ Task.connection_specification_name = "test2"
+ refute Task.connected?
+
+ Task.cache do
+ assert_queries(2) { Task.find(1); Task.find(1) }
+ end
+ ensure
+ ActiveRecord::Base.connection_handler.remove_connection(Task.connection_specification_name)
+ Task.connection_specification_name = spec_name
+ end
+
def test_query_cache_doesnt_leak_cached_results_of_rolled_back_queries
ActiveRecord::Base.connection.enable_query_cache!
post = Post.first