Testing Freegeoip IP Address Lookup Integration in Geocoder
This test suite validates the Freegeoip lookup functionality in the Geocoder gem, focusing on IP address geolocation capabilities and configuration options. The tests ensure accurate location data retrieval and proper handling of special IP address cases.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
alexreisner/geocoder
test/unit/lookups/freegeoip_test.rb
# encoding: utf-8
require 'test_helper'
class FreegeoipTest < GeocoderTestCase
def setup
super
Geocoder.configure(ip_lookup: :freegeoip)
end
def test_result_on_ip_address_search
result = Geocoder.search("74.200.247.59").first
assert result.is_a?(Geocoder::Result::Freegeoip)
end
def test_result_on_loopback_ip_address_search
result = Geocoder.search("127.0.0.1").first
assert_equal "127.0.0.1", result.ip
assert_equal 'RD', result.country_code
assert_equal "Reserved", result.country
end
def test_result_on_private_ip_address_search
result = Geocoder.search("172.19.0.1").first
assert_equal "172.19.0.1", result.ip
assert_equal 'RD', result.country_code
assert_equal "Reserved", result.country
end
def test_result_components
result = Geocoder.search("74.200.247.59").first
assert_equal "Plano, TX 75093, United States", result.address
end
def test_host_config
Geocoder.configure(freegeoip: {host: "local.com"})
lookup = Geocoder::Lookup::Freegeoip.new
query = Geocoder::Query.new("24.24.24.23")
assert_match %r(https://local\.com), lookup.query_url(query)
end
end