Simulate a HTTP request to action by specifying request method,
parameters and set/volley the response.
action: The controller action to call.
http_method: Request method used to send the http request.
Possible values are GET,POST,PATCH,PUT,DELETE,HEAD. Defaults to GET.
parameters: The HTTP parameters. This may be nil, a hash,
or a string that is appropriately encoded
(application/x-www-form-urlencoded or
multipart/form-data).
session: A hash of parameters to store in the session. This may be
nil.
flash: A hash of parameters to store in the flash. This may be
nil.
Example calling create action and sending two params:
Example sending parameters, nil session and setting a flash
message:
process:view,'GET',{id:7},nil,{notice:'This is flash message'}
To simulate GET,POST,PATCH,PUT,DELETE and HEAD requests prefer using #get, #post,
#patch, #put, #delete and #head methods
respectively which will make tests more expressive.
Note that the request method is not verified.
# File actionpack/lib/action_controller/test_case.rb, line 589
def process(action, http_method = 'GET', *args)
check_required_ivars
if args.first.is_a?(String) && http_method != 'HEAD'
@request.env['RAW_POST_DATA'] = args.shift
end
parameters, session, flash = args
parameters ||= {}
# Ensure that numbers and symbols passed as params are converted to
# proper params, as is the case when engaging rack.
parameters = paramify_values(parameters) if html_format?(parameters)
@html_document = nil
unless @controller.respond_to?(:recycle!)
@controller.extend(Testing::Functional)
end
@request.recycle!
@response.recycle!
@controller.recycle!
@request.env['REQUEST_METHOD'] = http_method
controller_class_name = @controller.class.anonymous? ?
"anonymous" :
@controller.class.controller_path
@request.assign_parameters(@routes, controller_class_name, action.to_s, parameters)
@request.session.update(session) if session
@request.flash.update(flash || {})
@controller.request = @request
@controller.response = @response
build_request_uri(action, parameters)
name = @request.parameters[:action]
@controller.recycle!
@controller.process(name)
if cookies = @request.env['action_dispatch.cookies']
unless @response.committed?
cookies.write(@response)
end
end
@response.prepare!
@assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {}
if flash_value = @request.flash.to_session_value
@request.session['flash'] = flash_value
end
@response
end