conn_case.ex 1.2 KB

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