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
2 Likes

This error is still present in B3.0.

2 Likes

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.

2 Likes

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

2 Likes

@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.

1 Like

On page 183, the link to redirect to stream_data lib by Andrea it doesn’t.

Glad I could help!

1 Like