我正在尝试从rails 4.2.6更新到rails 5.0.0.1,但在运行测试时会收到以下警告:
DEPRECATION WARNING:ActionController :: TestCase HTTP请求方法 将来只会接受Rails版本中的关键字参数。
示例:
get:show,params:{id:1},session:{user_id:1}进程:update, 方法:: post,params:{id:1}(从块中调用 在/home/ubuntu/workspace/my_app/test/controllers/tractions_controller_test.rb:25)
我一直在进行适当的更改以适应这种变化。但是对于下面的集成测试行,我不知道如何正确更改它:
delete api_sessions_path, { api_session: { org_id: nil } }, { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }
所以测试通过但是有弃用警告。如果我将其更改为下面的两个选项,则测试将失败并出现语法错误。如何正确调整线?
delete api_sessions_path, params: { api_session: { org_id: nil } }, { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }
delete api_sessions_path, params: { { api_session: { org_id: nil } }, { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email } }
更新:我也尝试将session
与以下选项一起使用,但会产生错误ArgumentError: unknown keyword: session
。
delete api_sessions_path, session: { api_session: { org_id: nil } }, params: { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }
delete api_sessions_path, params: { api_session: { org_id: nil } }, session: { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }
delete api_sessions_path, params: { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }, session: { api_session: { org_id: nil } }
delete api_sessions_path, session: { api_session: { org_id: nil } }, { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }
答案 0 :(得分:1)
我找到了解决方案。必须添加headers
标记:
delete api_sessions_path, params: { api_session: { org_id: nil } }, headers: { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }