0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

railsでcookies.signed, encryptedをテストする

Last updated at Posted at 2025-03-26

これはなに

rails の controller test において、cookies.signed を使用した cookieを検査する方法に関するメモ。

メモ

そもそもの問題点は、ActionDispatch::IntegrationTestではcookiesRack::Test::CookieJarが用いられる。
これはsignedencryptedを扱えない。

そこで、ActionDispatch::Cookies::CookieJarを用意する。

.rb
cookiejar = ActionDispatch::Cookies::CookieJar.build(request, cookies.to_hash)

これを用いることで、signed,encryptedを参照できる。

.rb
cookiejar.signed[:hoge] 
cookiejar.encrypted[:fuga] 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?