Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 467

Show
Ignore:
Timestamp:
01/20/05 14:43:59 (4 years ago)
Author:
david
Message:

Added TestResponse#binary_content that'll return as a string the data sent through send_data/send_file for testing #500 [Alexey]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r463 r467  
    11*SVN* 
     2 
     3* Added TestResponse#binary_content that'll return as a string the data sent through send_data/send_file for testing #500 [Alexey] 
    24 
    35* Added @request.env['RAW_POST_DATA'] for people who need access to the data before Ruby's CGI has parsed it #505 [bitsweat] 
  • trunk/actionpack/lib/action_controller/test_process.rb

    r402 r467  
    192192    end 
    193193 
     194    # Returns binary content (downloadable file), converted to a String 
     195    def binary_content 
     196      raise "Response body is not a Proc: #{body.inspect}" unless body.kind_of?(Proc) 
     197      require 'stringio' 
     198 
     199      sio = StringIO.new 
     200 
     201      begin  
     202        $stdout = sio 
     203        body.call 
     204      ensure 
     205        $stdout = STDOUT 
     206      end 
     207 
     208      sio.rewind 
     209      sio.read 
     210    end 
    194211end 
    195212