aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJames Coleman <jtc331@gmail.com>2016-08-22 14:21:28 -0400
committerJames Coleman <jtc331@gmail.com>2016-08-24 10:09:23 -0400
commit3df5173d006f190548d38da3445a0dc3af3858ef (patch)
treecd0b9a2cf97450ecaf1726f59cb2f8865356c7fd /activerecord/test/cases
parentae570a2ead7aa5fb78ef823a95ebbc7ed764a467 (diff)
downloadrails-3df5173d006f190548d38da3445a0dc3af3858ef.tar.gz
rails-3df5173d006f190548d38da3445a0dc3af3858ef.tar.bz2
rails-3df5173d006f190548d38da3445a0dc3af3858ef.zip
Test that AR query cache isn't busted when types are not same object
This is fixed in 5.0 as an ancillary part of 574f255629a45cd67babcfb9bb8e163e091a53b8 but here I also add a test for the condition. I'd previously backported the fix (and added a test) in the below commit; this brings the fix back up to master. (cherry picked from commit fce3dbf30241f2a65c777e192a7171b0eea81453)
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/query_cache_test.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb
index d99e8a1dc6..619a5f4f3f 100644
--- a/activerecord/test/cases/query_cache_test.rb
+++ b/activerecord/test/cases/query_cache_test.rb
@@ -212,6 +212,26 @@ class QueryCacheTest < ActiveRecord::TestCase
end
end
+ def test_query_cached_even_when_types_are_reset
+ Task.cache do
+ # Warm the cache
+ task = Task.find(1)
+
+ Task.connection.type_map.clear
+
+ # Preload the type cache again (so we don't have those queries issued during our assertions)
+ Task.connection.send(:initialize_type_map, Task.connection.type_map)
+
+ # Clear places where type information is cached
+ Task.reset_column_information
+ Task.initialize_find_by_cache
+
+ assert_queries(0) do
+ Task.find(1)
+ end
+ end
+ end
+
private
def middleware(&app)
executor = Class.new(ActiveSupport::Executor)