【发布时间】:2020-05-03 08:54:42
【问题描述】:
我正在尝试使用 Rspec 测试用于设计用户信息的补丁,更新 url 看起来像这样 # PATCH/PUT /api/users/1 但我在以下所有情况下都收到此错误
错误ArgumentError:
wrong number of arguments (given 2, expected 1)
我尝试过的案例
patch :update, {'id'=> @api_user['user']['id'], 'user' => attributes_for(:normal_user)}
patch :update, 'id'=> @api_user['user']['id'], 'user' => attributes_for(:normal_user)
patch :update, 'id'=> @api_user['user']['id'], :params => {'user' => attributes_for(:normal_user)}
我试过这个
patch :update, :params => {'user' => create(:normal_user)}。 # 这个id在里面
但是给出了这个错误
No route matches {:action=>"update", :controller=>"api/users", :user=>#<User id: 227794695, email: "test11@example.com", created_at: "2020-05-03 08:51:55", updated_at: "2020-05-03 08:51:55", is_admin: nil, first_name: "test", last_name: "test">} 有意义,url 应该是update/id
【问题讨论】:
标签: ruby-on-rails rspec devise