From 7eb0c4e29e567f02affc202b51eb277cbae43688 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 9 Sep 2009 10:02:49 -0700 Subject: handle bodies that do not respond to :close MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the wrapped Clogger object always responds to close, we cannot blindly delegate the close method to the body without ensuring it can be closed. So ensure that it can be closed before attempting to close it, all return values and errors are trapped and returned. Reported-by: IƱaki Baz Castillo --- test/test_clogger.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/test_clogger.rb') diff --git a/test/test_clogger.rb b/test/test_clogger.rb index e65311f..23d6e58 100644 --- a/test/test_clogger.rb +++ b/test/test_clogger.rb @@ -469,4 +469,24 @@ class TestClogger < Test::Unit::TestCase assert_equal "", s end + def test_clogger_body_not_closeable + s = '' + app = lambda { |env| [302, [ %w(a) ], []] } + cl = Clogger.new(app, :logger => s) + status, headers, body = cl.call(@req) + assert_nil body.close + end + + def test_clogger_body_close_return_value + s = '' + body = [] + def body.close + :foo + end + app = lambda { |env| [302, [ %w(a) ], body ] } + cl = Clogger.new(app, :logger => s) + status, headers, body = cl.call(@req) + assert_equal :foo, body.close + end + end -- cgit v1.2.3-24-ge0c7