From 5988bc28cd2834ed8163bd2248004d06f01643a8 Mon Sep 17 00:00:00 2001 From: Nick Quaranto and Josh Nichols Date: Sat, 8 Aug 2009 14:49:50 -0400 Subject: [PATCH] Adding a deprecation warning for output.flush when rendering a proc or lambda --- actionpack/lib/action_dispatch/http/response.rb | 6 ++++++ actionpack/test/dispatch/response_test.rb | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 03d1780..35e0ae3 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -168,6 +168,12 @@ module ActionDispatch # :nodoc: str end + def flush + ActiveSupport::Deprecation.warn( + 'Use of output.flush is no longer needed for streaming output, ' + + 'because ActionDispatch::Response automatically handles it', caller) + end + def set_cookie(key, value) if value.has_key?(:http_only) ActiveSupport::Deprecation.warn( diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 256ed06..dbb2feb 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -56,6 +56,23 @@ class ResponseTest < ActiveSupport::TestCase assert_equal ["0", "1", "2", "3", "4"], parts end + def test_streaming_block_with_flush_is_deprecated + @response.body = Proc.new do |response, output| + 5.times do |n| + output.write(n) + output.flush + end + end + + assert_deprecated(/output.flush is no longer needed/) do + @response.prepare! + status, headers, body = @response.to_a + + parts = [] + body.each { |part| parts << part } + end + end + test "content type" do [204, 304].each do |c| @response.status = c.to_s -- 1.6.1.2