diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-01-02 14:34:25 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-01-02 14:36:23 -0300 |
commit | dbe7fe289c8f32250bf6161e466d52f9d90154cf (patch) | |
tree | 67db5fa344f553a50a023e9a00a16727e822c260 /activerecord/test/cases | |
parent | ecdae459d209ae5144fd4390e8a6f247d7f98a1c (diff) | |
parent | c753ede62c0e554c26ddc5bf31137f86096bedb7 (diff) | |
download | rails-dbe7fe289c8f32250bf6161e466d52f9d90154cf.tar.gz rails-dbe7fe289c8f32250bf6161e466d52f9d90154cf.tar.bz2 rails-dbe7fe289c8f32250bf6161e466d52f9d90154cf.zip |
Merge pull request #17820 from fw42/restore_query_cache_on_rollback
Clear query cache on rollback
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/query_cache_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 9d89d6a1e8..744f9edc47 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -212,6 +212,38 @@ class QueryCacheTest < ActiveRecord::TestCase ensure ActiveRecord::Base.configurations = conf end + + def test_query_cache_doesnt_leak_cached_results_of_rolled_back_queries + ActiveRecord::Base.connection.enable_query_cache! + post = Post.first + + Post.transaction do + post.update_attributes(title: 'rollback') + assert_equal 1, Post.where(title: 'rollback').to_a.count + raise ActiveRecord::Rollback + end + + assert_equal 0, Post.where(title: 'rollback').to_a.count + + ActiveRecord::Base.connection.uncached do + assert_equal 0, Post.where(title: 'rollback').to_a.count + end + + begin + Post.transaction do + post.update_attributes(title: 'rollback') + assert_equal 1, Post.where(title: 'rollback').to_a.count + raise 'broken' + end + rescue Exception + end + + assert_equal 0, Post.where(title: 'rollback').to_a.count + + ActiveRecord::Base.connection.uncached do + assert_equal 0, Post.where(title: 'rollback').to_a.count + end + end end class QueryCacheExpiryTest < ActiveRecord::TestCase |