Hi! I believe I’ve found an erratum.
tl;dr: MessageController/create does not add changeset validation errors to the flash, which breaks one of its tests.
On page 182 we write this test:
test "invalid params is rejected", %{conn: conn} do
conn = post(conn, ~p"/messages/new", %{}) assert html_response(conn, 200) =~
Plug.HTML.html_escape("can't be blank")
end
Which resulted in this error when I ran it:
1) test POST /messages/new invalid params is rejected (PhoneAppWeb.MessageControllerTest)
test/phone_app_web/controllers/message_controller_test.exs:34
Assertion with =~ failed
code: assert html_response(conn, 200) =~ Plug.HTML.html_escape("can't be blank")
left: "<!DOCTYPE html>\n<html lang=\"en\" class=\"[scrollbar-gutter:stable]\">\n <head>
[rest of page truncated]
right: "can't be blank"
After some valuable Elixir debugging practice, I believe I have the cause. The test in this case is looking for a “can’t be blank” error somewhere on the page. In MessageController/create, there is code that takes errors and puts them into the flash on line 48. However, that code is never reached because changeset validation happens on line 43 and the error shoots us down to line 55. That error handler doesn’t do anything specifically with the error. It passes the changeset to the view to render, but I don’t see where in the view it would display the error. Thus, the validation error doesn’t appear on the rendered view, and the test can’t find it.
Thanks, and just let me know if I’ve gotten something wrong.