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?
1 Like
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.
You’re most definitely right. I hit this even before trying it out (haven’t turned page 119 right now), because I couldn’t figure out mentally how check_field returning :ok should work, and came here to see if it’s an error in the book. Thanks!