Designing Elixir Systems with OTP: Fix Mastery.Boundary.Validator.check_field() (page 118)

When testing the code of page 118 in iex -S mix i think you should get:

iex(1)> Mastery.Boundary.QuizValidator.errors(%{mastery: 3})
[title: "is required"]

But instead you get:

iex(1)> Mastery.Boundary.QuizValidator.errors(%{mastery: 3})
:ok

This could be fixed by changing the first line of Page 118 (lib\mastery\boundary\validator.ex) from

  defp check_field(:ok, _errors, _field_name), do: :ok

to

  defp check_field(:ok, errors, _field_name), do: errors

Is this right?

When using the fix from above, test driving the API (page 124) returns

iex(3)> Mastery.build_quiz Math.quiz_fields
[title: "must be a string"]

Which seem right, because either the Mastery.Examples.Math.quiz_fields() must be changed (it should return an string for title) or the Mastery.Boundary.QuizValidator.validate_title() must be changed (it should check for atoms not for strings).

Either way, to get :ok for iex(3)> Mastery.build_quiz Math.quiz_fields and iex(4)> Mastery.add_template Math.quiz.title, Math.template_fields instead of [] the validation calls in Mastery.build_quiz and Mastery.add_template (Build the API Layer Page 122) must check for []return values instead of :ok.

Still questioning myself if I’m on a wrong path here.