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.
It turns out that it does not seem possible to do this.
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!
Just use session[:user]
without open_session
block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With