diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-02 11:30:49 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-02 11:30:49 -0700 |
commit | 951e18abea9c116fc5d6b330ca1dcd2890abe006 (patch) | |
tree | 5a9a57e72dd1d68af5b1e0883d74ff10057cf63b /activerecord/test | |
parent | 4300855e7dccb06017e6d8de203c60497e5a5321 (diff) | |
download | rails-951e18abea9c116fc5d6b330ca1dcd2890abe006.tar.gz rails-951e18abea9c116fc5d6b330ca1dcd2890abe006.tar.bz2 rails-951e18abea9c116fc5d6b330ca1dcd2890abe006.zip |
introduce a body proxy to ensure that query cache is enabled during streaming
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/query_cache_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 66ec592cca..b2e40c6b22 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -10,6 +10,7 @@ class QueryCacheTest < ActiveRecord::TestCase def setup Task.connection.clear_query_cache + ActiveRecord::Base.connection.disable_query_cache! end def test_middleware_delegates @@ -39,6 +40,31 @@ class QueryCacheTest < ActiveRecord::TestCase mw.call({}) end + def test_cache_on_during_body_write + streaming = Class.new do + def each + yield ActiveRecord::Base.connection.query_cache_enabled + end + end + + mw = ActiveRecord::QueryCache.new lambda { |env| + [200, {}, streaming.new] + } + body = mw.call({}).last + body.each { |x| assert x, 'cache should be on' } + body.close + assert !ActiveRecord::Base.connection.query_cache_enabled, 'cache disabled' + end + + def test_cache_off_after_close + mw = ActiveRecord::QueryCache.new lambda { |env| } + body = mw.call({}).last + + assert ActiveRecord::Base.connection.query_cache_enabled, 'cache enabled' + body.close + assert !ActiveRecord::Base.connection.query_cache_enabled, 'cache disabled' + end + def test_find_queries assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) { Task.find(1); Task.find(1) } end |