aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/caching/fragments.rb4
-rw-r--r--actionpack/test/controller/caching_test.rb15
2 files changed, 17 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb
index 95cba0e411..4ef600bea0 100644
--- a/actionpack/lib/action_controller/caching/fragments.rb
+++ b/actionpack/lib/action_controller/caching/fragments.rb
@@ -36,8 +36,8 @@ module ActionController #:nodoc:
def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
if perform_caching
- if cache = read_fragment(name, options)
- buffer.concat(cache)
+ if fragment_exist?(name,options)
+ buffer.concat(read_fragment(name, options))
else
pos = buffer.length
block.call
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index c286976315..68529cc8f7 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -625,6 +625,21 @@ class FragmentCachingTest < ActionController::TestCase
assert !fragment_computed
assert_equal 'generated till now -> fragment content', buffer
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
class FunctionalCachingController < ActionController::Base