Programming Phoenix LiveView: B10 typos (page 12-100)

Some typos and confusing bits I’ve noticed in the first 100 pages or so:

  • pp 12: “Now, start the web server” – the output snippet should include the mix phx.server command. It’s listed on the previous page in the output from mix phx.new pento but no harm including it here (as with mix ecto.create).
  • pp 13: “You may have noticed that Phoenix fetched the dependencies on this list when you ran mix deps.get.” – I don’t remember mix deps.get being mentioned before. That was presumably triggered implicitly by running the phx.new or phx.server task?
  • pp 51: we'll execute the log_in_user/3 function implement by
    • implemented by
  • pp 62: When a live view first mounts in it’s disconnected states/it's/its
  • pp 69: We get six failures. – I got 108 failures on first run of mix test, so maybe the generated set of tests is bigger now… or it’s the result of attempting one of the exercises.
  • pp 70: But even after adding :register_and_log_in_user I get 108 failures that look like this:
     test/pento_web/live/product_live_test.exs:19
     ** (Postgrex.Error) ERROR 23502 (not_null_violation) null value in column "username" of relation "users" violates not-null constraint

         table: users
         column: username

     Failing row contains (628, user-576460752303420725@example.com, $2b$04$MBV9BcBPEKPQZo1Go1tTSOypd4ecjocA5rw9BzqvocXmLGWf0y7Xm, null, 2024-02-29 23:57:26, 2024-02-29 23:57:26, null).
  • I believe this happened because the exercise on page 61 involves adding a username field. I added it as unique and non-null in the migration and validations, but the generator in accounts_fixtures.ex didn’t know about it. Maybe it adds fields based on the registration_changeset function, where I hadn’t added username to the cast call.
    • Also, I tried mix ecto.reset a few times but found it didn’t delete tables… turns out I needed MIX_ENV=test mix ecto.reset

Then:

  1) test register user creates account and logs the user in (PentoWeb.UserRegistrationLiveTest)
     test/pento_web/live/user_registration_live_test.exs:40
     ** (ArgumentError) could not find non-disabled input, select or textarea with name "user[username]" within:

To fix this, I added a username field to lib/pento_web/live/user_registration_live.ex. Another test failure required the addition of :username to the changeset.required test. I’m a bit wary of this sort of test coupling, where the test just duplicates and restates the implementation.

  • pp 74: The Ecto.Changeset.cast/4 function filters the user data we pass into params.s/params/attrs
  • pp 80: Changeset ares/set/sets