samedi 28 mai 2016

Phoenix Framework: What's the correct way to seed database for testing?

I am building my first Phoenix app and am trying to write a test that will verify that the user retrieved from a JWT in a connection's Authentication header is the correct user, is authenticated, etc.

What is the correct way to seed the database with a single record for this test?

Should it be done:

  • globally, using the test/test_helper.exs file, by requiring priv/repo/seeds.exs and executing manual Ecto operations

OR

  • per test (in which case I am not certain how best to proceed)

Finally, what is the correct way to clean out the test database after successfully running my tests, so I can avoid trying to create the same record every time I run a test?

Aucun commentaire:

Enregistrer un commentaire