0

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?

Sam Houston
  • 3,413
  • 2
  • 30
  • 46

2 Answers2

2

I believe this is already handled for you when running Ecto in sandbox mode, which is the way Phoenix generates the test cases.

bratsche
  • 2,666
  • 20
  • 23
1

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
PatNowak
  • 5,721
  • 1
  • 25
  • 31