gpt4 book ai didi

ruby-on-rails - rails : How do I disable protect_from_forgery in tests only?

转载 作者:行者123 更新时间:2023-12-02 22:43:37 25 4
gpt4 key购买 nike

我正在对我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com