Last active
February 26, 2016 16:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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