
scottswezey
Testing Elixir: logic error in code sample: with_authenticated_user/1 (Page 25)
The with_authenticated_user/1
code sample on PDF page 25 in B2.0 returns the user
object, and not the authenticated_user
object as I expect it should. Leaving the code as-is would probably be considered a logic error in a real application, and may be confusing to some readers of the book.
Current code:
def with_authenticated_user(context) do
user = User.create(%{name: "Bob Robertson"})
authenticated_user = TestHelper.authenticate(user)
Map.put(context, :authenticated_user, user) # Error here
end
Fixed code:
def with_authenticated_user(context) do
user = User.create(%{name: "Bob Robertson"})
authenticated_user = TestHelper.authenticate(user)
Map.put(context, :authenticated_user, authenticated_user) # Fixed
end
Marked As Solved

idlehands
@scottswezey As we are prepping for production, I finally made this fix. Thanks again for catching it. It was a great call out. Alas, the sample code probably won’t be updated until the book is finalized.
Also Liked

scottswezey
This error is still present in B3.0.

idlehands
Thanks! I’m sorry we missed this in the last release. The errata system currently leaves a bit to be desired. We will make sure the code is updated for the next beta.

idlehands
I lied. But it will be updated by the time we roll out the final. Sorry… been a bit overwhelmed.
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /centos
- /ash
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /slackware
- /julia
- /c
- /neovim