To make a long story short: it keeps happening that I sometimes forget to put an Ecto.Repo
into sandbox mode. And this then leads to issues with OTHER tests when the inserted data collides with the entries inserted for this test. Afterwards I have to go for a hunt for the offending test.
What I’d like to do is put my Repo into a “fail any write unless it’s sandboxed”-mode. This way any “rogue” test would immediately break when I try to insert something after forgetting to sandbox.
I’ve looked at
- Postgres and whether or not I can enforce any writes to happen inside of transactions (not even sure if that’d do the trick)
- Ecto.Repo callbacks and whether there is one we can use to check if the connection is in sandbox mode
So far I’ve found nothing that fits the bill. How would I go about this?
Note: Please refrain from telling me I should define a DataCase
and use that for my tests. This is all the case. But not all tests require DB access so some use “straight-forward” ExUnit.Case
s, and occasionally a mix up happens. We’re all human. And I’d like the machine to tell me when I screw up.