According to the Rails Edge Guide all ActionDispatch::IntegrationTest HTTP requests take optional named keyword arguments:
get post_url, params: { id: 12 }, session: { user_id: 5 }
Great. Now, I've got the following code in a controller test:
test 'should redirect from login page if user is logged in' do
get '/login', session: { user_id: users(:stephen).id }
assert_redirected_to root_url, 'Expected redirect to root'
end
And when I run it, my test fails and I see the following deprecation warning:
ActionDispatch::IntegrationTest HTTP request methods will accept only
the following keyword arguments in future Rails versions:
params, headers, env, xhr
So obviously it's rails is not letting me pass a keyword argument named session.
Furthermore, both of the old methods of setting the session in a functional test no longer work either:
test "some thing" do
session[:user_id] = users(:stephen).id
# etc
end
NoMethodError: undefined method `session' for nil:NilClass
And this fails too:
test "some thing" do
get '/login', nil, nil, { user_id: users(:stephen).id }
# etc
end
The session hash is just ignored and the deprecation warning about rails only accepting 4 different named arguments appears.
Is anyone else having this sort of trouble with Rails 5.rc1?
get post_url, params: { id: 12 }, session: { user_id: 5 }
the second argument is params,get '/login', session: { user_id: users(:stephen).id }
but you pass the session, have you triedget '/login', params: {}, session: { user_id: users(:stephen).id }
? – Parton