Closed bcardarella closed 8 years ago
Still a work in progress, don't merge yet
You'll want to do this:
Repo.insert(build_changeset(email: "test@example.com")
|> with_changeset
|> assert_invalid_field(:email)
@danmcclain what is the reason for requiring with_changeset
? Why can we just pass the changeset directly into assert_invalid_field
?
We do that to be able to pass a lambda so that you don't have to define the changeset function in your Model module
Could you document the assert_(in)valid_fields
?
One minor issue: by calling assert_valid_field
via Enum.each
, it will stop at the first error. If possible, it would be nice to collect the fields that are (in)valid so that we could show a single message with all the failed constraints
@danmcclain I am aware of that issue. For now I need to get this function in so I can move forward with SOG. If you want to open an issue about error collection it can be addressed in the future
@danmcclain updated
Adds:
ValidField.assert_valid_field/2
ValidField.assert_valid_fields/2
ValidField.assert_invalid_field/2
ValidField.assert_invalid_fields/2
These functions should be used to assert constraints. Constraints need to hit the database in order to fire.
Changesets can now be passed directly into assertions if they are already created.