Reputation: 45943
Consider the following integration test:
test "if there is no user in session, redirect to index and flash message" do
open_session do |sess|
post '/login', :email => users(:client).email, :password => 'rumpelstiltskin'
sess[:user] = nil
get '/user_page'
assert_redirected_to index_path
assert_equal "Your session has expired. Please log in again", flash[:notice]
end
end
This generates error: undefined method '[]='
And, changing to sess.session[:user] = nil
generates an error as well: NoMethodError: undefined method 'session' for nil:NilClass
How do you modify the session params from an integration test in Rails?
Working in Rails 3.0.7, Ruby 1.9.2p180, Unit test framework.
EDIT:
get '/user_page', nil, {:user => nil}
and get ('/user_page', nil, {:user => nil} )
generate errors.
Upvotes: 11
Views: 7942
Reputation: 49172
This isn't what integration tests are designed for. You shouldn't modify the session directly, instead you should hit your /logout path.
Upvotes: 0
Reputation: 536
In Rails 3.2.3 the following seems to work for me:
# Hit the root_path to start our session
get root_path
# A helper method to set our session
login_as(@user_fixture)
# Now we can access the session variable
assert session[:user_id]
Not sure if this will work for you, so goodluck!
Upvotes: 5