scottswezey

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

idlehands

Author of Testing Elixir

@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

scottswezey

This error is still present in B3.0.

idlehands

idlehands

Author of Testing Elixir

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

idlehands

Author of Testing Elixir

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

Popular Prag Prog topics Top

johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New
dachristenson
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New

Latest in PragProg

View all threads ❯