Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed Integration Test of the “remember me” Checkbox

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.

like image 355
rilutham Avatar asked Nov 28 '14 08:11

rilutham


1 Answers

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.

like image 135
aljachimiak Avatar answered Oct 24 '22 23:10

aljachimiak