instance method process

Ruby on Rails 4.2.9

Since v3.0.20

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

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 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:

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

action req
http_method opt = 'GET'
args rest
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

Type at least 2 characters to search.

↑↓ navigate · open · esc close