I'm working on michal hart's Ruby on rails tutorial at chapter 8 Click here for details, I get stuck at exercise 8.6, The author introduced a way to access the virtual remember_token attribute in the integration test and he left some work for us,
assert_equal assigns(:user).FILL_IN, FILL_IN
Im supposed to replace the correct code with "FILL_IN" placeholder. I just couldn't think of the correct one. I tried with
assert_equal assigns(:user).cookies, remember_token
app/controllers/sessions_controller.rb
def create
@user = User.find_by(email: params[:session][:email].downcase)
if @user && @user.authenticate(params[:session][:password])
log_in @user
params[:session][:remember_me] == '1' ? remember(@user) : forget(@user)
redirect_to @user
But it didn't work, Erros:
"test_login_with_remembering", UsersLoginTest, 0.590876]
test_login_with_remembering#UsersLoginTest (0.59s)
NoMethodError: NoMethodError: undefined method `cookies' for #<User:0x007f964f1a91d0>
I know it's something very simple, I actually did some research , it seems no one has asked the same question, because the tutorial is quite new. Please understand that I'm just a beginner,I would be greatly appreciated , if you can help me to solve this problem.
I have got the answer by purchasing Michael's book. And the answer is included in the solution manual. I think it's worth to share since i have asked this question
assert_equal assigns(:user).remember_token, cookies['remember_token']
It's worth nothing that, Reading about ruby language will be greatly helpful to understand this code,My problem was i didn't do much reading about Ruby before I dive in rails studies, But it's not a big problem, I have just moved on to Ruby beginning in order to get a deeper understanding about Ruby language! Good luck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With