From c69476c828220fd059e1721ca2abeaf9792d1972 Mon Sep 17 00:00:00 2001 From: Nick Quaranto and Josh Nichols Date: Sat, 8 Aug 2009 18:10:55 -0400 Subject: [PATCH] Adding a deprecation warning for output.flush when rendering a proc or lambda --- actionpack/lib/action_controller/base.rb | 1 - actionpack/lib/action_controller/response.rb | 7 +++++++ actionpack/test/controller/rack_test.rb | 19 ++++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 0801bd6..1d8cc14 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -819,7 +819,6 @@ module ActionController #:nodoc: # render :text => proc { |response, output| # 10_000_000.times do |i| # output.write("This is line #{i}\n") - # output.flush # end # } # diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb index def03fa..0a3ca20 100644 --- a/actionpack/lib/action_controller/response.rb +++ b/actionpack/lib/action_controller/response.rb @@ -166,6 +166,13 @@ module ActionController # :nodoc: str end + def flush + ActiveSupport::Deprecation.warn( + 'Use of output.flush is no longer needed for streaming output, ' + + 'because ActionController::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/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index b550d3d..aeace2b 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -class BaseRackTest < Test::Unit::TestCase +class BaseRackTest < ActiveSupport::TestCase def setup @env = { "HTTP_MAX_FORWARDS" => "10", @@ -261,6 +261,23 @@ class RackResponseTest < BaseRackTest body.each { |part| parts << part } 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 end class RackResponseHeadersTest < BaseRackTest -- 1.6.1.2