At the request of a customer, I had to implement sending a notification email every time the application detects two active sessions for the same user from different IP addresses. How do you test this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Created integration test test/integration/multiple_ip_test.rb
Integration tests look a lot like functional tests, but there are some differences. You cannot use
@requestto change the origin IP address. This is why I had to open theActionController::Requestclass and redefine theremote_ipmethod.Because the response to
post_via_redirectis always 200, instead of usingassert_response :redirectI use the URL to verify the user has logged in successfully.The call to
reset!is necessary to start a new session.For an introduction on integration tests, check the Rails Guides on testing, unfortunately they do not mention the
reset!method.