aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/query_cache_test.rb
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2016-06-21 11:30:00 -0400
committerJon Moss <me@jonathanmoss.me>2016-06-21 11:30:00 -0400
commit5118a3b8b00b9f15dc2b71c281f2b814ea5d14ab (patch)
tree838406d89ad183bae8a92984ba41483b2fa289f0 /activerecord/test/cases/query_cache_test.rb
parent7ad8093b0eaff02bda6bb2999e8a81a481667aab (diff)
downloadrails-5118a3b8b00b9f15dc2b71c281f2b814ea5d14ab.tar.gz
rails-5118a3b8b00b9f15dc2b71c281f2b814ea5d14ab.tar.bz2
rails-5118a3b8b00b9f15dc2b71c281f2b814ea5d14ab.zip
Add explicit testing for `uncached` vs. `cached`
There are a ton of middleware related tests in this file, and it seems like `cached vs. `uncached` is being neglected. Added in a test to confirm the expected behavior.
Diffstat (limited to 'activerecord/test/cases/query_cache_test.rb')
-rw-r--r--activerecord/test/cases/query_cache_test.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb
index d5c01315c1..9ae98daf9c 100644
--- a/activerecord/test/cases/query_cache_test.rb
+++ b/activerecord/test/cases/query_cache_test.rb
@@ -190,6 +190,27 @@ class QueryCacheTest < ActiveRecord::TestCase
Task.connection_specification_name = spec_name
end
+ def test_query_cache_executes_new_queries_within_block
+ ActiveRecord::Base.connection.enable_query_cache!
+
+ # Warm up the cache by running the query
+ assert_queries(1) do
+ assert_equal 0, Post.where(title: 'test').to_a.count
+ end
+
+ # Check that if the same query is run again, no queries are executed
+ assert_queries(0) do
+ assert_equal 0, Post.where(title: 'test').to_a.count
+ end
+
+ ActiveRecord::Base.connection.uncached do
+ # Check that new query is executed, avoiding the cache
+ assert_queries(1) do
+ assert_equal 0, Post.where(title: 'test').to_a.count
+ end
+ end
+ end
+
def test_query_cache_doesnt_leak_cached_results_of_rolled_back_queries
ActiveRecord::Base.connection.enable_query_cache!
post = Post.first