diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index d0094b6d..04af9cb8 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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 diff --git a/test/response_test.rb b/test/response_test.rb index 826defdc..6c70b60a 100644 --- a/test/response_test.rb +++ b/test/response_test.rb @@ -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