8

I am following railstutorial.org 3rd Edition and I am currently working on Chapter 8: Log in, log out.

I found an issue in Listing 8.51 (login without remembering test):

assert_nil cookies['remember_token']

When I execute: rake test, it's return RED with the following error:

FAIL["test_login_without_remembering", UsersLoginTest, 1.268578948]
 test_login_without_remembering#UsersLoginTest (1.27s)
    Expected "" to be nil.
    test/integration/users_login_test.rb:46:in `block in      <class:UsersLoginTest>'

Otherwise, when I change to the following code, it is returning GREEN and the Log In - Log out process work properly.

assert_not_nil cookies['remember_token']

Anyone who faces the same issue can explain this case?

Thank you.

rilutham
  • 491
  • 5
  • 10
  • Where's the code being tested, or at least the link to this exercise you're doing? – lcguida Nov 28 '14 at 10:44
  • @rockskull I am following tutorial in this [link](https://www.railstutorial.org/book/log_in_log_out#sec-remember_tests) (8.4.6 point) and my code is exactly the same as in that tutorial. But, when i run test in Listing 8.52, it is return RED. – rilutham Nov 29 '14 at 05:38

1 Answers1

22

I just made this mistake...

TL;DR; remove remember user from sessions_controller.rb


Take a look at Listing 8.34. You should find remember user in the session_controller.rb.

Now in reference to the same file, take a look at Listing 8.49. The author makes a big deal about this line, but if you just paste it in without removing the call to remember user, the token will still get generated.

So, when pasting in this line:

params[:session][:remember_me] == '1' ? remember(user) : forget(user)

make sure it is replacing the call to remember user.

aljachimiak
  • 356
  • 2
  • 5