是否可以验证为使用 Rails 集成测试设置的 cookie 的域?
我正在使用以下技术为我们的域设置通配符 cookie:
cookies['root_domain_flash_warning'] = {
'value' => 'mistakes have been made!',
'domain' => ".#{APP_DOMAIN}",
'expires' => 2.minutes.from_now
}
这似乎很方便。 不幸的是,除了与传递给 CookieJar#[]= 的散列中的“value”键关联的值之外,我似乎无法查找任何内容,因为 CookieJar#[] 实际上并不返回传递给其的选项散列。互惠法。
有谁知道在功能测试中验证已设置 cookie 的域的方法吗?
I'm using the following technique to set a wild-card cookie for our domain:
cookies['root_domain_flash_warning'] = {
'value' => 'mistakes have been made!',
'domain' => ".#{APP_DOMAIN}",
'expires' => 2.minutes.from_now
}
Which seems to work handily. Unfortunately I can't seem to look up anything but the value associated with the 'value' key in the hash passed to CookieJar#[]= because of the fact that CookieJar#[] doesn't actually return the options hash passed to its reciprocal method.
Does anyone know of a way of verifying the domain a cookie has been set for in a functional test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检查
Set-Cookie
标头的值,该标头可在@response.headers['Set-Cookie']
中访问。请尝试以下操作:
不幸的是,您无法从
cookies
方法中提取这些值。 在ActionController::Integration::Session#process
源代码 (actionpack/lib/action_controller/integration.rb
) 中,集成测试 cookie 的处理如下,仅提取输入哈希的value
部分:You could check the value of the
Set-Cookie
header which can be accessed in@response.headers['Set-Cookie']
.Try something along these lines:
You can't extract these values from the
cookies
method, unfortunately. In theActionController::Integration::Session#process
source (actionpack/lib/action_controller/integration.rb
), the integration test cookies are processes as below, which only extracts thevalue
part of the input hash: