Testing an Ecto Schema as a Data Validator

It’s very common in web applications to do some basic validation of user input in the controller so that if easy-to-detect issues are present, the application doesn’t spend time doing work (or calling the database) when there isn’t a chance of success. The code that we have already written takes input and casts it to the appropriate value, returning errors for any data that can’t be cast or for any required parameters that are missing. This is exactly the kind of basic validation that we’re talking about. With some very minor changes, we will update our code to serve as a validator. After that, we will update our refactored tests to reflect the changes.

As mentioned, our code already does the work we ...

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.