From 2025 year from Rails 7.2.2.1.
For me work this variant:
another_ip = IPAddr.new('127.1.2.3').to_s
@request.headers['REMOTE_ADDR'] = another_ip
get '/admin/login'
# if you debugging in your code, then
=> #<ActionController::TestRequest GET "http://admin/auth" for 127.1.2.3>