DEV Community

Discussion on: Testing signed and encrypted cookies in Rails

Collapse
 
chaadow profile image
Chad Lee B. • Edited

Update: I've figured out how to make it work in my tests ( was having weird issues but application related, not rails related)

Basically to make this work in Rails/minitest, one would do:

jar = ActionDispatch::Cookies::CookieJar.build(request, response.cookies)
Enter fullscreen mode Exit fullscreen mode

We would need to use response.cookies. No need to add .to_hash because response.cookies is already a hash.

Unlike Rspec, cookies in Minitest ( or Rails custom version of minitest) always refer to the request cookies which is an instance of Rack::Test::CookieJar

Thread Thread
 
bubbaspaarx profile image
Edward Sparks • Edited

This is the answer I have been looking for. I had originally used

jar = ActionDispatch::Cookies::CookieJar.build(request, cookies.to_hash).signed
Enter fullscreen mode Exit fullscreen mode

But realised late on that the cookies.to_hash was empty as I never set cookies in Rack::Test::CookieJar

Thank you for this