我只是尝试使用下面的代码来测试通过 Rspec 请求规范中的设计路径更新用户的电子邮件,我想知道它为什么给我错误:ActionController::UnknownFormat:
require 'rails_helper'
RSpec.describe "UsersEdits", type: :request do
let(:user) { FactoryGirl.create(:user) }
it "my test" do
email = "new@email.com"
params = { "user[email]" => email, "user[current_password]" => 'foobar' }
put user_registration_path(user), params
user.reload
expect(user.email).to eq(email)
end
end
这是错误:
Failure/Error: patch user_registration_path(user), params
ActionController::UnknownFormat:
ActionController::UnknownFormat
任何帮助将不胜感激,谢谢!
最佳答案
刚刚完成了我自己的追踪。user_registration_path(user)
将生成 "/users.980190962"
这会导致 ActionController::UnknownFormat
错误。在某些 Controller 设置中,您可能会修补 "/users/980790962"
,但只设计补丁 "/users"
直接地。我猜想设计/看守补丁无论登录用户是谁并且不需要用户 ID。所以与其:
patch user_registration_path, params: { user: {
....
} }
或对于 rspec:
put user_registration_path, params
关于ruby-on-rails - 测试设计使用 Rspec 更新用户注册信息并获取:ActionController::UnknownFormat: Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38252638/