From fe1e038e80b6330fe8cd97c3eba36e8fb84312b6 Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Sun, 16 Mar 2014 23:31:07 -0400
Subject: [PATCH] Fix country code bug in :maxmind_local.
---
lib/geocoder/lookups/maxmind_local.rb | 2 +-
lib/geocoder/results/maxmind_local.rb | 2 +-
test/unit/lookups/maxmind_local_test.rb | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/geocoder/lookups/maxmind_local.rb b/lib/geocoder/lookups/maxmind_local.rb
index 8fcea68a..0fa5d867 100644
--- a/lib/geocoder/lookups/maxmind_local.rb
+++ b/lib/geocoder/lookups/maxmind_local.rb
@@ -42,7 +42,7 @@ module Geocoder::Lookup
addr = IPAddr.new(query.text).to_i
q = "SELECT country, country_code FROM maxmind_geolite_country
WHERE start_ip_num <= #{addr} AND #{addr} <= end_ip_num"
- format_result(q, [:country_name, :country_code])
+ format_result(q, [:country_name, :country_code2])
end
end
diff --git a/lib/geocoder/results/maxmind_local.rb b/lib/geocoder/results/maxmind_local.rb
index 6f3f9c43..81b545ab 100644
--- a/lib/geocoder/results/maxmind_local.rb
+++ b/lib/geocoder/results/maxmind_local.rb
@@ -29,7 +29,7 @@ module Geocoder::Result
end
def country_code
- @data[:country_code]
+ @data[:country_code2]
end
def postal_code
diff --git a/test/unit/lookups/maxmind_local_test.rb b/test/unit/lookups/maxmind_local_test.rb
index 751fd92b..630eb1f9 100644
--- a/test/unit/lookups/maxmind_local_test.rb
+++ b/test/unit/lookups/maxmind_local_test.rb
@@ -14,7 +14,7 @@ class MaxmindLocalTest < GeocoderTestCase
assert_equal 'Mountain View', result.city
assert_equal 'CA', result.state
assert_equal 'United States', result.country
- assert_equal 'USA', result.country_code
+ assert_equal 'US', result.country_code
assert_equal '94043', result.postal_code
assert_equal 37.41919999999999, result.latitude
assert_equal -122.0574, result.longitude
--
GitLab