instance method
process
Ruby on Rails 4.2.9
Since v3.0.20Signature
process(action, http_method = 'GET', *args)
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 areGET,POST,PATCH,PUT,DELETE,HEAD. Defaults toGET. -
parameters: The HTTP parameters. This may benil, a hash, or a string that is appropriately encoded (application/x-www-form-urlencodedormultipart/form-data). -
session: A hash of parameters to store in the session. This may benil. -
flash: A hash of parameters to store in the flash. This may benil.
Example calling create action and sending two params:
process :create, 'POST', user: { name: 'Gaurish Sharma', email: 'user@example.com' }
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.
Parameters
-
actionreq -
http_methodopt = 'GET' -
argsrest
Source
# File actionpack/lib/action_controller/test_case.rb, line 595
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
@html_scanner_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
Defined in actionpack/lib/action_controller/test_case.rb line 595
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::TestCase::Behavior