Hi, all!
I was wondering if there is any way to have ExUnit tests to print validation failure messages from changesets when it seeds the database.
I have this validate_inclusion changeset for a field, and I just spent an awful lot of time testing this one model completely oblivious of a typo I made in my seed script because I thought the message would pop up to me in test if the validation would fail.
I’m probably missing something fundamental on how either ExUnit or changesets work.
Did you use Repo.insert! or Repo.update! when using the changeset, or did you use Repo.insert or Repo.update. The ! versions of the functions will raise if the changeset fails, whereas the non ! versions will return {:ok, result} | {:error, error} tuples. If you want a noisy failure, use !.
Also… it might be a silly question, but writing code using the bang version is best practice or available mostly for troubleshooting?
Cause when I use it I get all sorts of CaseClauseError that I don’t even understand, but everything seems to work fine when I use the version without it. It makes me feel like I shouldn’t be leaving it like this haha