Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8465715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:07:46+00:00 2026-06-10T15:07:46+00:00

At the request of a customer, I had to implement sending a notification email

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:07:48+00:00Added an answer on June 10, 2026 at 3:07 pm

    Created integration test test/integration/multiple_ip_test.rb

    require 'test_helper'
    
    @@default_ip = "127.0.0.1"
    
    class ActionController::Request
      def remote_ip
        @@default_ip
      end
    end
    
    class MultipleIpTest < ActionDispatch::IntegrationTest
      fixtures :all
    
      test "send email notification if login from different ip address" do
        post_via_redirect login_path,
                          :user => {:username => "john", :password => "test"}
        assert_equal "/users/john", path
    
        reset!
        @@default_ip = "200.1.1.1"
        post_via_redirect login_path,
                          :user => {:username => "john", :password => "test"}
        assert_equal "/users/john", path
        assert_equal 1, ActionMailer::Base.deliveries.size
      end
    end
    

    Integration tests look a lot like functional tests, but there are some differences. You cannot use @request to change the origin IP address. This is why I had to open the ActionController::Request class and redefine the remote_ip method.

    Because the response to post_via_redirect is always 200, instead of using assert_response :redirect I 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our marketing department comes back with active directory integration being a key customer request,
I am creating a site for our customer service department to request password rest
public ActionResult DisplayCustomer() { Customer objCustomer = new Customer(); objCustomer.Id = Convert.ToInt16(Request.Form[Customerid]); objCustomer.CustomerCode =
I have a model: class Customer(models.Model): name = models.CharField(max_length=200) email = models.EmailField() company =
Due to wierd request from a Customer, I have managed to figure out how
I am making an AJAX request for XML. I am doing this every second.
I've got a request from a customer to automatically detect the type of mobile
I am creating an Android application for a customer which will be pre-installed and
We have a request from many customers to make our datepickers reflect the date
I need to setup a system where customers can choose to Request a Quote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.