Method: ActionController::TestCase::Behavior#get

Defined in:
actionpack/lib/action_controller/test_case.rb

#get(action, **args) ⇒ Object

Simulate a GET request with the given parameters.

  • ‘action`: The controller action to call.

  • ‘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`.

You can also simulate POST, PATCH, PUT, DELETE, and HEAD requests with ‘post`, `patch`, `put`, `delete`, and `head`. Example sending parameters, session, and setting a flash message:

get :show,
  params: { id: 7 },
  session: { user_id: 1 },
  flash: { notice: 'This is flash message' }

Note that the request method is not verified. The different methods are available to make the tests more expressive.



429
430
431
# File 'actionpack/lib/action_controller/test_case.rb', line 429

def get(action, **args)
  process(action, method: "GET", **args)
end