Rails 5 deprecation warning for tests

橙三吉。 提交于 2019-12-11 06:36:23

问题


I'm trying to update from rails 4.2.6 to rails 5.0.0.1 but get the following warning when running my tests:

DEPRECATION WARNING: ActionController::TestCase HTTP request methods will accept only keyword arguments in future Rails versions.

Examples:

get :show, params: { id: 1 }, session: { user_id: 1 } process :update, method: :post, params: { id: 1 } (called from block in at /home/ubuntu/workspace/my_app/test/controllers/tractions_controller_test.rb:25)

I've been making the appropriate changes to accommodate for this change. However for the integration test line below, I don't know how to change it properly:

delete api_sessions_path, { api_session: { org_id: nil } }, { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }

So the test passes but with the deprecation warning. If I change it to the two options below the test fails with a syntax error. How to properly adjust the line?

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 } }

Update: I've also tried using session with the options below but that produces the error 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 }

回答1:


I found the solution. The headers tag had to be added:

delete api_sessions_path, params: { api_session: { org_id: nil } }, headers: { "HTTP_API_TOKEN": "token", "HTTP_USER_EMAIL": @user.email }


来源:https://stackoverflow.com/questions/40227372/rails-5-deprecation-warning-for-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!