handle setting body to a Rack::Response

This commit is contained in:
Konstantin Haase 2011-05-13 11:00:05 +02:00
parent 48de22a81e
commit b0aca8d075
2 changed files with 11 additions and 0 deletions

View File

@ -60,6 +60,7 @@ module Sinatra
# http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
class Response < Rack::Response
def body=(value)
value = value.body while value.respond_to? :body and value.body != value
@body = value.respond_to?(:to_str) ? [value.to_str] : value
end

View File

@ -39,4 +39,14 @@ class ResponseTest < Test::Unit::TestCase
assert_equal '14', headers['Content-Length']
assert_equal @response.body, body.body
end
it 'does not nest a Sinatra::Response' do
@response.body = Sinatra::Response.new ["foo"]
assert_equal @response.body, ["foo"]
end
it 'does not nest a Rack::Response' do
@response.body = Rack::Response.new ["foo"]
assert_equal @response.body, ["foo"]
end
end