Initial commit: there's still tons of base Phoenix boilerplate to remove, but the...
[tech-radar-editor.git] / test / support / conn_case.ex
1 defmodule TechRadarEditor.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 and query models.
9
10 Finally, if the test case interacts with the database,
11 it cannot be async. For this reason, every test runs
12 inside a transaction which is reset at the beginning
13 of the test unless the test case is marked as async.
14 """
15
16 use ExUnit.CaseTemplate
17
18 using do
19 quote do
20 # Import conveniences for testing with connections
21 use Phoenix.ConnTest
22
23 alias TechRadarEditor.Repo
24 import Ecto
25 import Ecto.Changeset
26 import Ecto.Query
27
28 import TechRadarEditor.Router.Helpers
29
30 # The default endpoint for testing
31 @endpoint TechRadarEditor.Endpoint
32 end
33 end
34
35 setup tags do
36 :ok = Ecto.Adapters.SQL.Sandbox.checkout(TechRadarEditor.Repo)
37
38 unless tags[:async] do
39 Ecto.Adapters.SQL.Sandbox.mode(TechRadarEditor.Repo, {:shared, self()})
40 end
41
42 {:ok, conn: Phoenix.ConnTest.build_conn()}
43 end
44 end