作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在对我的 Rails 应用程序进行集成测试,我想测试具有无效数据(即角色=>“管理员”)的自定义 POST 是否得到正确处理 - 通过被忽略或显示错误消息。
问题是,authenticity_token 很难设置。
有没有一种简单的方法可以在进行测试时停用 protect_from_forgery - 或者至少进行一次测试?
最佳答案
在你的应用程序 Controller 中
protect_from_forgery unless Rails.env.test?
关于ruby-on-rails - rails : How do I disable protect_from_forgery in tests only?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10388742/
我是一名优秀的程序员,十分优秀!