ValidField

ValidField allows for unit testing values against a changeset. It is assumed that the changeset function is defined on the model you are testing.

Summary

Functions

Raises an ExUnit.AssertionError when the values for the field are valid for the model provided. Returns the original model to allow subsequent calls to be piped

Raises an ExUnit.AssertionError when the values for the field are invalid for the model provided. Returns the original model to allow subsequent calls to be piped

Functions

assert_invalid_field(model, field, values)

Specs

assert_invalid_field(Ecto.Model.t, atom, list) :: Ecto.Model.t

Raises an ExUnit.AssertionError when the values for the field are valid for the model provided. Returns the original model to allow subsequent calls to be piped

Examples

iex> ValidField.assert_invalid_field(%Model{}, :first_name, [nil])
...> |> ValidField.assert_invalid_field(:first_name, [""])
iex> ValidField.assert_invalid_field(%Model{}, :first_name, ["Test"])
** (ExUnit.AssertionError) Expected the following values to be invalid for "first_name": "Test"
assert_valid_field(model, field, values)

Specs

assert_valid_field(Ecto.Model.t, atom, list) :: Ecto.Model.t

Raises an ExUnit.AssertionError when the values for the field are invalid for the model provided. Returns the original model to allow subsequent calls to be piped

Examples

iex> ValidField.assert_valid_field(%Model{}, :first_name, ["Test"])
...> |> ValidField.assert_valid_field(:last_name, ["Value"])
iex> ValidField.assert_valid_field(%Model{}, :first_name, [nil, ""])
** (ExUnit.AssertionError) Expected the following values to be valid for "first_name": nil, ""