Flowdock
process(action, method: "GET", params: nil, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil) public

Simulate an HTTP request to action by specifying request method, parameters and set/volley the response.

  • action: The controller action to call.

  • method: Request method used to send the HTTP request. Possible values are GET, POST, PATCH, PUT, DELETE, HEAD. Defaults to GET. Can be a symbol.

  • params: The hash with HTTP parameters that you want to pass. This may be nil.

  • body: The request body with 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.

  • format: Request format. Defaults to nil. Can be string or symbol.

  • as: Content type. Defaults to nil. Must be a symbol that corresponds to a mime type.

Example calling create action and sending two params:

process :create,
  method: 'POST',
  params: {
    user: { name: 'Gaurish Sharma', email: 'user@example.com' }
  },
  session: { user_id: 1 },
  flash: { 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.

It’s not recommended to make more than one request in the same test. Instance variables that are set in one request will not persist to the next request, but it’s not guaranteed that all Rails internal state will be reset. Prefer ActionDispatch::IntegrationTest for making multiple requests in the same test.

Note that the request method is not verified.

Show source
Register or log in to add new notes.