| 1 |
18 |
defmodule DaProductAppWeb.ConnCase do |
| 2 |
|
@moduledoc """ |
| 3 |
|
This module defines the test case to be used by |
| 4 |
|
tests that require setting up a connection. |
| 5 |
|
|
| 6 |
|
Such tests rely on `Phoenix.ConnTest` and also |
| 7 |
|
import other functionality to make it easier |
| 8 |
|
to build common data structures and query the data layer. |
| 9 |
|
|
| 10 |
|
Finally, if the test case interacts with the database, |
| 11 |
|
we enable the SQL sandbox, so changes done to the database |
| 12 |
|
are reverted at the end of every test. If you are using |
| 13 |
|
PostgreSQL, you can even run database tests asynchronously |
| 14 |
|
by setting `use DaProductAppWeb.ConnCase, async: true`, although |
| 15 |
|
this option is not recommended for other databases. |
| 16 |
|
""" |
| 17 |
|
|
| 18 |
|
use ExUnit.CaseTemplate |
| 19 |
|
|
| 20 |
4 |
using do |
| 21 |
|
quote do |
| 22 |
|
# The default endpoint for testing |
| 23 |
|
@endpoint DaProductAppWeb.Endpoint |
| 24 |
|
|
| 25 |
|
use DaProductAppWeb, :verified_routes |
| 26 |
|
|
| 27 |
|
# Import conveniences for testing with connections |
| 28 |
|
import Plug.Conn |
| 29 |
|
import Phoenix.ConnTest |
| 30 |
|
import DaProductAppWeb.ConnCase |
| 31 |
|
end |
| 32 |
|
end |
| 33 |
|
|
| 34 |
|
setup tags do |
| 35 |
14 |
DaProductApp.DataCase.setup_sandbox(tags) |
| 36 |
|
{:ok, conn: Phoenix.ConnTest.build_conn()} |
| 37 |
|
end |
| 38 |
|
end |