diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 29306668c7b2a..bd76b3f61dd93 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added TestResponse#binary_content that'll return as a string the data sent through send_data/send_file for testing #500 [Alexey] + * Added @request.env['RAW_POST_DATA'] for people who need access to the data before Ruby's CGI has parsed it #505 [bitsweat] * Fixed that a default fragment store wan't being set to MemoryStore as intended. diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 6fd5249836067..2ab955b6777d9 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -191,6 +191,23 @@ def cookies headers['cookie'].inject({}) { |hash, cookie| hash[cookie.name] = cookie; hash } end + # Returns binary content (downloadable file), converted to a String + def binary_content + raise "Response body is not a Proc: #{body.inspect}" unless body.kind_of?(Proc) + require 'stringio' + + sio = StringIO.new + + begin + $stdout = sio + body.call + ensure + $stdout = STDOUT + end + + sio.rewind + sio.read + end end class TestSession #:nodoc: