diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-01-03 18:43:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-03 18:43:16 -0500 |
commit | 032fe34803233d242927873b5559b4efc5ca215a (patch) | |
tree | 1985b590d820de1007ea7bbe41133c5a09b78f7e | |
parent | 530e5ff910bf033aa29bba722662457fc69d3d63 (diff) | |
parent | 5118a3b8b00b9f15dc2b71c281f2b814ea5d14ab (diff) | |
download | rails-032fe34803233d242927873b5559b4efc5ca215a.tar.gz rails-032fe34803233d242927873b5559b4efc5ca215a.tar.bz2 rails-032fe34803233d242927873b5559b4efc5ca215a.zip |
Merge pull request #25460 from maclover7/jm-uncached
Add explicit testing for `uncached` vs. `cached`
-rw-r--r-- | activerecord/test/cases/query_cache_test.rb | 21 |
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 4a49bfe9b1..4c47a487ac 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -275,6 +275,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 |