Method: ActionController::TestCase::Behavior#process
- Defined in:
- lib/action_controller/test_case.rb
#process(action, http_method = 'GET', *args) ⇒ Object
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: '[email protected]' }
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.
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File '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 = @request.env['action_dispatch.cookies'] unless @response.committed? .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 |