private
def logged_user=(user)
+ reset_session
if user && user.is_a?(User)
User.current = user
session[:user_id] = user.id
else
User.current = User.anonymous
- session[:user_id] = nil
end
end
end
assert user.hashed_password.blank?
end
+ def test_login_and_logout_should_clear_session
+ get '/login'
+ sid = session.session_id
+
+ post '/login', :username => 'admin', :password => 'admin'
+ assert_redirected_to 'my/page'
+ assert_not_equal sid, session.session_id, "login should reset session"
+ assert_equal 1, session[:user_id]
+ sid = session.session_id
+
+ get '/'
+ assert_equal sid, session.session_id
+
+ get '/logout'
+ assert_not_equal sid, session.session_id, "logout should reset session"
+ assert_nil session[:user_id]
+ end
+
else
puts 'Mocha is missing. Skipping tests.'
end