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 changset provided. Returns the original changset map from with_changeset/1
to allow subsequent calls to be piped
Raises an ExUnit.AssertionError when the values for the field are invalid for the changset provided. Returns the original changset map from with_changeset/1
to allow subsequent calls to be piped
Returns a changeset map to be used with assert_valid_field/3
or assert_invalid_field/3
. When with_changeset is passed a single arguments, it is assumed to be an Ecto Model struct and will call the changeset
function on the struct's module
Returns a changeset map to be used with assert_valid_field/3
or assert_invalid_field/3
. The function passed to with_changeset/2
must accept two arguments, the first being the model provided to with_changeset/2
, the second being the map of properties to be applied in the changeset
Functions
Specs
assert_invalid_field(map, atom, list) :: map
Raises an ExUnit.AssertionError when the values for the field are valid for the changset provided. Returns the original changset map from with_changeset/1
to allow subsequent calls to be piped
Examples
iex> ValidField.with_changeset(%Model{})
...> |> ValidField.assert_invalid_field(:first_name, [nil])
...> |> ValidField.assert_invalid_field(:first_name, [""])
iex> ValidField.with_changeset(%Model{})
...> |> ValidField.assert_invalid_field(:first_name, ["Test"])
** (ExUnit.AssertionError) Expected the following values to be invalid for "first_name": "Test"
Specs
assert_valid_field(map, atom, list) :: map
Raises an ExUnit.AssertionError when the values for the field are invalid for the changset provided. Returns the original changset map from with_changeset/1
to allow subsequent calls to be piped
Examples
iex> ValidField.with_changeset(%Model{})
...> |> ValidField.assert_valid_field(:first_name, ["Test"])
...> |> ValidField.assert_valid_field(:last_name, ["Value"])
iex> ValidField.with_changeset(%Model{})
...> |> ValidField.assert_valid_field(:first_name, [nil, ""])
** (ExUnit.AssertionError) Expected the following values to be valid for "first_name": nil, ""
Specs
with_changeset(Ecto.Model.t) :: map
Returns a changeset map to be used with assert_valid_field/3
or assert_invalid_field/3
. When with_changeset is passed a single arguments, it is assumed to be an Ecto Model struct and will call the changeset
function on the struct's module
Examples
iex> ValidField.with_changeset(%Model{})
...> |> ValidField.assert_invalid_field(:first_name, [nil])
...> |> ValidField.assert_invalid_field(:first_name, [""])
Specs
with_changeset(Ecto.Model.t, function) :: map
Returns a changeset map to be used with assert_valid_field/3
or assert_invalid_field/3
. The function passed to with_changeset/2
must accept two arguments, the first being the model provided to with_changeset/2
, the second being the map of properties to be applied in the changeset.
Examples
iex> ValidField.with_changeset(%Model{}, &Model.changeset/2)
...> |> ValidField.assert_invalid_field(:first_name, [nil])
...> |> ValidField.assert_invalid_field(:first_name, [""])