Phoenix.ConnTest
SourceSummary↑
clear_flash(conn) | Clears up the flash storage |
conn() | Creates a connection to be used in upcoming requests |
conn(method, path, params_or_body \\ nil) | Creates a connection to be used in upcoming requests with a preset method, path and body |
connect(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
delete(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
delete_req_cookie(conn, key) | Deletes a request cookie |
delete_req_header(conn, key) | Deletes a request header |
dispatch(conn, endpoint, method, path_or_action, params_or_body \\ nil) | Dispatches the connection to the given endpoint |
ensure_recycled(conn) | Ensures the connection is recycled if it wasn’t already |
fetch_flash(conn) | Fetches the flash storage |
get(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
get_flash(conn) | Gets the whole flash storage |
get_flash(conn, key) | Gets the given key from the flash storage |
head(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
options(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
patch(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
post(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
put(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
put_flash(conn, key, value) | Puts the given value under key in the flash storage |
put_req_cookie(conn, key, value) | Puts a request cookie |
put_req_header(conn, key, value) | Puts a new request header |
recycle(conn) | Recycles the connection |
trace(conn, path_or_action, params_or_body \\ nil) | Dispatches to the current endpoint |
Functions
Specs:
- clear_flash(Plug.Conn.t) :: Plug.Conn.t
Clears up the flash storage.
Specs:
- conn :: Plug.Conn.t
- conn :: Plug.Conn.t
Creates a connection to be used in upcoming requests.
Creates a connection to be used in upcoming requests with a preset method, path and body.
This is useful when a specific connection is required for testing a plug or a particular function.
Specs:
- delete_req_cookie(Plug.Conn.t, binary) :: Plug.Conn.t
Deletes a request cookie.
Specs:
- delete_req_header(Plug.Conn.t, binary) :: Plug.Conn.t
Deletes a request header.
Dispatches the connection to the given endpoint.
When invoked via get/3
, post/3
and friends, the endpoint
is automatically retrieved from the @endpoint
module
attribute, otherwise it must be given as an argument.
The connection will be configured with the given method
,
path_or_action
and params_or_body
.
If path_or_action
is a string, it is considered to be the
request path and stored as so in the connection. If an atom,
it is assumed to be an action and the connection is dispatched
to the given action.
Parameters and body
This function, as well as get/3
, post/3
and friends, accept the
request body or parameters as last argument:
get conn(), "/", some: "param"
get conn(), "/", "some=param&url=encoded"
The allowed values are:
nil
- meaning there is no bodya binary - containing a request body. For such cases,
:headers
must be given as option with a content-type- a map or list - containing the parameters which will automatically set the content-type to multipart. The map or list may contain other lists or maps and all entries will be normalized to string keys
Ensures the connection is recycled if it wasn’t already.
See recycle/1
for more information.
Specs:
- fetch_flash(Plug.Conn.t) :: Plug.Conn.t
Fetches the flash storage.
Specs:
- get_flash(Plug.Conn.t) :: Plug.Conn.t
Gets the whole flash storage.
Specs:
- get_flash(Plug.Conn.t, term) :: Plug.Conn.t
Gets the given key from the flash storage.
Specs:
- put_flash(Plug.Conn.t, term, term) :: Plug.Conn.t
Puts the given value under key in the flash storage.
Specs:
- put_req_cookie(Plug.Conn.t, binary, binary) :: Plug.Conn.t
Puts a request cookie.
Specs:
- put_req_header(Plug.Conn.t, binary, binary) :: Plug.Conn.t
Puts a new request header.
Previous entries of the same header are overridden.
Specs:
- recycle(Plug.Conn.t) :: Plug.Conn.t
- recycle(Plug.Conn.t) :: Plug.Conn.t
Recycles the connection.
Recycling receives an connection and returns a new connection, containing cookies and relevant information from the given one.
This emulates behaviour performed by browsers where cookies returned in the response are available in following requests.
Note recycle/1
is automatically invoked when dispatching
to the endpoint, unless the connection has already been
recycled.
Macros
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.
Dispatches to the current endpoint.
See dispatch/5
for more information.