Licet.Testing (Licet v0.1.0)

Copy Markdown View Source

Helpers for testing code that uses Licet.

Licet works with Ecto.Adapters.SQL.Sandbox: a test's writes stay in its sandbox transaction and its checks see them. These helpers cover the two things the sandbox doesn't do on its own. See Testing.

Summary

Functions

Lets pid use the sandbox connection owned by parent.

Creates Licet's tables for prefix through repo.

Functions

allow(repo, parent, pid)

@spec allow(module(), pid(), pid()) :: :ok

Lets pid use the sandbox connection owned by parent.

Call it when a process started by the test calls Licet. It does nothing when repo doesn't use the sandbox pool.

Examples

test_pid = self()

Task.async(fn ->
  Licet.Testing.allow(MyApp.Repo, test_pid, self())
  Licet.check(MyApp.Licet, "document:1", "view", "user:ada")
end)

migrate!(repo, prefix)

@spec migrate!(module(), String.t()) :: :ok

Creates Licet's tables for prefix through repo.

Run it in a test's setup to give each test its own prefix and instance. Inside the sandbox, the tables are rolled back with the rest of the test.

Examples

setup do
  prefix = "t#{System.unique_integer([:positive])}"
  Licet.Testing.migrate!(MyApp.Repo, prefix)
  %{prefix: prefix}
end