class MockCGI
Constants
- BOUNDARY
- FILENAME
Attributes
session_id[R]
session_options[R]
upload_id[R]
Public Class Methods
new(size=1000, url='/test', &block)
click to toggle source
Calls superclass method
# File lib/upload_progress/test/multipart_progress_testx.rb, line 121 def initialize(size=1000, url='/test', &block) @url = url @env = {} @sio = MockIO.new('') { block.call(self) if block_given? } @upload_id = '1' add_param('param1', 'value1') add_data(size) add_param('param1', 'value2') add_end_boundary init_env @sio.rewind super() end
Public Instance Methods
env_table()
click to toggle source
# File lib/upload_progress/test/multipart_progress_testx.rb, line 145 def env_table @env end
stdinput()
click to toggle source
def stdinput_without_progress
@sio
end
# File lib/upload_progress/test/multipart_progress_testx.rb, line 141 def stdinput @sio end
Private Instance Methods
add_boundary()
click to toggle source
# File lib/upload_progress/test/multipart_progress_testx.rb, line 184 def add_boundary @sio << "--" << BOUNDARY << EOL end
add_data(size)
click to toggle source
# File lib/upload_progress/test/multipart_progress_testx.rb, line 176 def add_data(size) add_boundary @sio << "Content-Disposition: form-data; name=\"file\"; filename=\"#{FILENAME}\"" << EOL @sio << "Content-Type: application/octet-stream" << EOL << EOL @sio << "." * size @sio << EOL end
add_end_boundary()
click to toggle source
# File lib/upload_progress/test/multipart_progress_testx.rb, line 188 def add_end_boundary @sio << "--" << BOUNDARY << "--" << EOL end
add_param(name, value)
click to toggle source
# File lib/upload_progress/test/multipart_progress_testx.rb, line 170 def add_param(name, value) add_boundary @sio << "Content-Disposition: form-data; name=\"#{name}\"" << EOL << EOL @sio << value.to_s << EOL end
init_env()
click to toggle source
# File lib/upload_progress/test/multipart_progress_testx.rb, line 150 def init_env @env['HTTP_HOST'] = 'localhost' @env['SERVER_PORT'] = '80' @env['REQUEST_METHOD'] = "POST" @env['QUERY_STRING'] = @url.split('?')[1] || "upload_id=#{upload_id}&query_param=query_value" @env['REQUEST_URI'] = @url @env['SCRIPT_NAME'] = @url.split('?').first.split('/').last @env['PATH_INFO'] = @url.split('?').first @env['CONTENT_TYPE'] = "multipart/form-data; boundary=#{BOUNDARY}" @env['CONTENT_LENGTH'] = @sio.tell - EOL.size @session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.inject({}) { |options, pair| options[pair.first.to_s] = pair.last; options } session = CGI::Session.new({}, @session_options.merge({'new_session' => true})) @session_id = session.session_id @env['COOKIE'] = "_session_id=#{session.session_id}" session.close end