Skip to content

Instantly share code, notes, and snippets.

@kcurtin
Last active February 26, 2016 16:39
Show Gist options
  • Save kcurtin/9aa37bfe6203973c1ce1 to your computer and use it in GitHub Desktop.
Save kcurtin/9aa37bfe6203973c1ce1 to your computer and use it in GitHub Desktop.
Using case templates to setup your database for integration tests with elixir and ecto.
defmodule DBTransactions do
use ExUnit.CaseTemplate
setup_all do
Ecto.Adapters.SQL.begin_test_transaction(Repo)
on_exit fn ->
Ecto.Adapters.SQL.rollback_test_transaction(Repo)
end
end
setup do
Ecto.Adapters.SQL.restart_test_transaction(Repo, [])
end
end
# Use it in your test module
defmodule MessageTest do
use DBTransactions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment