Permalink
Browse files

ensure query cache is cleared when Rack body is closed, fixes bug rep…

…orted on 951e18a
  • Loading branch information...
1 parent bd4831d commit 38d92d705e18d953bb0d8f4ba5d156755572acfb @tenderlove tenderlove committed May 4, 2011
Showing with 12 additions and 0 deletions.
  1. +1 −0 activerecord/lib/active_record/query_cache.rb
  2. +11 −0 activerecord/test/cases/query_cache_test.rb
@@ -40,6 +40,7 @@ def each(&block)
def close
@target.close if @target.respond_to?(:close)
ensure
+ ActiveRecord::Base.connection.clear_query_cache
unless @original_cache_value
ActiveRecord::Base.connection.disable_query_cache!
end
@@ -65,6 +65,17 @@ def test_cache_off_after_close
assert !ActiveRecord::Base.connection.query_cache_enabled, 'cache disabled'
end
+ def test_cache_clear_after_close
+ mw = ActiveRecord::QueryCache.new lambda { |env|
+ Post.find(:first)
+ }
+ body = mw.call({}).last
+
+ assert !ActiveRecord::Base.connection.query_cache.empty?, 'cache not empty'
+ body.close
+ assert ActiveRecord::Base.connection.query_cache.empty?, 'cache should be empty'
+ end
+
def test_find_queries
assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) { Task.find(1); Task.find(1) }
end

0 comments on commit 38d92d7

Please sign in to comment.