Day 10

Cookie troubles

Still struggling with cookies today. Finally found a way to set a cookie in my test, have it show up in my controller, and then return to the test again, but it doesn’t seem like the right way. Here’s what I have:

cookies["token"] = @device.token
get root_url, headers: { "HTTP_COOKIE" => "token=#{@device.token}" }
assert_response :success
assert_equal @device.token, cookies["token"]

In my application controller, I’m checking for the token and using it to determine who the current user is. This works, and may have to work for now, but setting/passing in the cookie twice seems really weird. I dug into all kinds of documentation, but couldn’t find a better way. Hopefully I’ll come across something else soon. I may post in Stack Overflow tomorrow and see if I can find some help there, but I need to move on to other features. This has taken way too long already.