gpt4 book ai didi

ruby-on-rails - 如何解决此 "positional arguments in functional tests has been deprecated"警告?

转载 作者:行者123 更新时间:2023-12-04 17:53:43 26 4
gpt4 key购买 nike

Rails 5 在我的测试中引入了一些弃用信息

DEPRECATION WARNING: Using positional arguments in functional tests has been deprecated,
in favor of keyword arguments, and will be removed in Rails 5.1.

Deprecated style:
get :show, { id: 1 }, nil, { notice: "This is a flash message" }

New keyword style:
get :show, params: { id: 1 }, flash: { notice: "This is a flash message" },
session: nil # Can safely be omitted.

在大多数情况下,这些问题很容易解决。消息中的说明非常清楚。

但我仍然收到这些关于测试强参数的 Controller 规范的警告。

应如何重写以下内容以准备 Rails 5.1?

let(:user) { create :user }
it { is_expected.to permit( :name, :email ).for(:update, params: { id: user.to_param, user: valid_attributes } ).on(:user) }

最佳答案

尝试:

for(:update, params: { params: { id: user.to_param, user: valid_attributes } })  

它很丑,但对我有用。

更新:在这里找到了我的解决方法和修复号 https://github.com/thoughtbot/shoulda-matchers/issues/867

关于ruby-on-rails - 如何解决此 "positional arguments in functional tests has been deprecated"警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42188827/

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