Skip to content
Browse files

with_output_buffer cannot assume there's an output_buffer

[#4182 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent c937da9 commit a594a22267bfd3346e00923742c4aa7edad0cef7 @fxn fxn committed with jeremy
View
2 actionpack/lib/action_view/helpers/capture_helper.rb
@@ -140,7 +140,7 @@ def content_for?(name)
def with_output_buffer(buf = nil) #:nodoc:
unless buf
buf = ActionView::OutputBuffer.new
- buf.force_encoding(output_buffer.encoding) if buf.respond_to?(:force_encoding)
+ buf.force_encoding(output_buffer.encoding) if output_buffer && buf.respond_to?(:force_encoding)
end
self.output_buffer, old_buffer = buf, output_buffer
yield
View
6 actionpack/test/template/capture_helper_test.rb
@@ -12,4 +12,10 @@ def test_content_for
assert content_for?(:title)
assert ! content_for?(:something_else)
end
+
+ def test_with_output_buffer_does_not_assume_there_is_an_output_buffer
+ av = ActionView::Base.new
+ assert_nil av.output_buffer
+ assert_equal "", av.with_output_buffer {}
+ end
end

0 comments on commit a594a22

Please sign in to comment.
Something went wrong with that request. Please try again.