Permalink
Browse files

Fixed double output from cache in no caching mode

  • Loading branch information...
1 parent eb69721 commit 585f8f27b190637fd0bad67d7d611eed5ae262e7 @dhh dhh committed Jun 8, 2010
Showing with 14 additions and 29 deletions.
  1. +14 −14 actionpack/lib/action_view/helpers/cache_helper.rb
  2. +0 −15 actionpack/test/controller/caching_test.rb
@@ -32,27 +32,27 @@ module CacheHelper
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
- safe_concat fragment_for(name, options, &block)
+ if controller.perform_caching
+ safe_concat(fragment_for(name, options, &block))
+ else
+ yield
+ end
+
nil
end
private
# TODO: Create an object that has caching read/write on it
def fragment_for(name = {}, options = nil, &block) #:nodoc:
- if controller.perform_caching
- if controller.fragment_exist?(name, options)
- controller.read_fragment(name, options)
- else
- # VIEW TODO: Make #capture usable outside of ERB
- # This dance is needed because Builder can't use capture
- pos = output_buffer.length
- yield
- fragment = output_buffer.slice!(pos..-1)
- controller.write_fragment(name, fragment, options)
- end
+ if controller.fragment_exist?(name, options)
+ controller.read_fragment(name, options)
else
- ret = yield
- ActiveSupport::SafeBuffer.new(ret) if ret.is_a?(String)
+ # VIEW TODO: Make #capture usable outside of ERB
+ # This dance is needed because Builder can't use capture
+ pos = output_buffer.length
+ yield
+ fragment = output_buffer.slice!(pos..-1)
+ controller.write_fragment(name, fragment, options)
end
end
end
@@ -644,21 +644,6 @@ def test_expire_fragment_with_regexp
assert_equal 'will not expire ;-)', @store.read('views/primalgrasp')
end
- def test_fragment_for_with_disabled_caching
- @controller.perform_caching = false
-
- @store.write('views/expensive', 'fragment content')
- fragment_computed = false
-
- view_context = @controller.view_context
-
- buffer = 'generated till now -> '.html_safe
- buffer << view_context.send(:fragment_for, 'expensive') { fragment_computed = true }
-
- assert fragment_computed
- assert_equal 'generated till now -> ', buffer
- end
-
def test_fragment_for
@store.write('views/expensive', 'fragment content')
fragment_computed = false

0 comments on commit 585f8f2

Please sign in to comment.