Fixes "Cached fragment hit" written to log even if fragment is not cached (Erik Andrejko) [#2917 state:resolved]
This commit is contained in:
parent
0fbeaa98e4
commit
efcfce50c4
@ -36,8 +36,8 @@ def fragment_cache_key(key)
|
|||||||
|
|
||||||
def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
|
def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
|
||||||
if perform_caching
|
if perform_caching
|
||||||
if cache = read_fragment(name, options)
|
if fragment_exist?(name,options)
|
||||||
buffer.concat(cache)
|
buffer.concat(read_fragment(name, options))
|
||||||
else
|
else
|
||||||
pos = buffer.length
|
pos = buffer.length
|
||||||
block.call
|
block.call
|
||||||
|
@ -625,6 +625,21 @@ def test_fragment_for
|
|||||||
assert !fragment_computed
|
assert !fragment_computed
|
||||||
assert_equal 'generated till now -> fragment content', buffer
|
assert_equal 'generated till now -> fragment content', buffer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_fragment_for_logging
|
||||||
|
fragment_computed = false
|
||||||
|
|
||||||
|
@controller.class.expects(:benchmark).with('Cached fragment exists?: views/expensive')
|
||||||
|
@controller.class.expects(:benchmark).with('Cached fragment miss: views/expensive')
|
||||||
|
@controller.class.expects(:benchmark).with('Cached fragment hit: views/expensive').never
|
||||||
|
|
||||||
|
buffer = 'generated till now -> '
|
||||||
|
@controller.fragment_for(buffer, 'expensive') { fragment_computed = true }
|
||||||
|
|
||||||
|
assert fragment_computed
|
||||||
|
assert_equal 'generated till now -> ', buffer
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class FunctionalCachingController < ActionController::Base
|
class FunctionalCachingController < ActionController::Base
|
||||||
|
Loading…
Reference in New Issue
Block a user