Testing Your Schema Through Database Calls
While we have a decent basic schema defined, we haven’t covered a subset of the kinds of logic that you’ll find in changeset functions—code that requires interaction with the database to verify that it works. The validations we’ve tested so far have laid out a pattern for us that can be used with other validations beyond cast/3 and validate_required/2. Functions your code can call that can be tested in similar ways include (but are not limited to) validate_inclusion/4, validate_length/3, and validate_subset/4. A very common case where things are easier to test with a database is a unique constraint on a column in your database. In this section, we’ll add a new field to our schema and table, including ...
Get Testing Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.