Reputation: 3661
More specifically I have a Phoenix Application using Ecto and Repo. I would like to flush my database after running each Exunit test which alters the database.
One way I could accomplish this would be to run all of the change
functions in the migrations in priv/repo/migrations/
directory, but I feel that there should be a nicer way.
Perhaps something like running the flush function?
Upvotes: 0
Views: 692
Reputation: 5812
If you would collect these side-effected tests into one file, you could use setup callback, like this:
setup do
for model <- [list modules you want to clear], do: Repo.delete_all(model)
end
Upvotes: 1
Reputation: 2674
I believe this is already handled for you when running Ecto in sandbox mode, which is the way Phoenix generates the test cases.
Upvotes: 2