gpt4 book ai didi

ruby-on-rails - Rspec 将 GET 参数传递给 PUT 操作

转载 作者:行者123 更新时间:2023-12-04 03:12:38 25 4
gpt4 key购买 nike

我正在尝试测试对 Controller 的 PUT 请求,但我需要向操作发送 GET 和 POST 正文参数。参数不能混合在一起,因为代码的某些部分显式访问 GET 参数。

如何将 GET 参数传递给 put 操作?

我有这个测试:

it "updates the account password to the provided value" do
put(:update, @params)
@account.reload.crypted_password.should == PasswordAccount.encrypt(@newpass, @account.password_salt)
end

如何向发送到操作的查询字符串添加“ token ”参数?

最佳答案

put 方法在 Rails 的 ActionController::TestCase::Behavior 中定义:

http://api.rubyonrails.org/classes/ActionController/TestCase/Behavior.html#method-i-put

据我所知,不支持分离不同的 get/post 参数,但为什么不将其包含在 @params 变量中呢?

put(:update, @params.merge(:token => 'gobbledygook'))

当您的代码看到参数时,Rails 已经为您合并了获取/发布参数。

喂,大卫

关于ruby-on-rails - Rspec 将 GET 参数传递给 PUT 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5505568/

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