From 1031443bd89f91f18453d537a114d3ad93981d3f Mon Sep 17 00:00:00 2001
From: Fernando Morgenstern <contato@fernandomarcelo.com>
Date: Sun, 1 Sep 2013 19:40:50 -0300
Subject: [PATCH] Change maxmind local to return an empty array when nothing is
 found.

Previously it was returning an exception which is not the same behavior as the other lookups.
---
 lib/geocoder/lookups/maxmind_local.rb | 4 +++-
 test/maxmind_local_test.rb            | 8 ++++++++
 test/test_helper.rb                   | 6 +++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/geocoder/lookups/maxmind_local.rb b/lib/geocoder/lookups/maxmind_local.rb
index 62ed2d64..1045b748 100644
--- a/lib/geocoder/lookups/maxmind_local.rb
+++ b/lib/geocoder/lookups/maxmind_local.rb
@@ -33,7 +33,9 @@ module Geocoder::Lookup
         )
       end
       
-      [GeoIP.new(configuration[:database]).city(query.to_s).to_hash]
+      result = GeoIP.new(configuration[:database]).city(query.to_s)
+      
+      result.nil? ? [] : [result.to_hash]
     end
   end
 end
\ No newline at end of file
diff --git a/test/maxmind_local_test.rb b/test/maxmind_local_test.rb
index cf18b210..cf72b778 100644
--- a/test/maxmind_local_test.rb
+++ b/test/maxmind_local_test.rb
@@ -16,4 +16,12 @@ class MaxmindLocalTest < Test::Unit::TestCase
     assert_equal result.latitude, 37.41919999999999
     assert_equal result.longitude, -122.0574
   end
+
+  def test_it_returns_empty_results_when_nothing_is_found
+    g = Geocoder::Lookup::MaxmindLocal.new
+
+    result = g.search(Geocoder::Query.new('127.0.0.1'))
+    
+    assert result.empty?, "Result wasn't empty."
+  end
 end
\ No newline at end of file
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 8b1facaf..9c43f469 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -145,7 +145,11 @@ module Geocoder
       def results query
         return [] if query.to_s == "no results"
 
-        [{:request=>"8.8.8.8", :ip=>"8.8.8.8", :country_code2=>"US", :country_code3=>"USA", :country_name=>"United States", :continent_code=>"NA", :region_name=>"CA", :city_name=>"Mountain View", :postal_code=>"94043", :latitude=>37.41919999999999, :longitude=>-122.0574, :dma_code=>807, :area_code=>650, :timezone=>"America/Los_Angeles"}]
+        if query.to_s == '127.0.0.1'
+          []
+        else
+          [{:request=>"8.8.8.8", :ip=>"8.8.8.8", :country_code2=>"US", :country_code3=>"USA", :country_name=>"United States", :continent_code=>"NA", :region_name=>"CA", :city_name=>"Mountain View", :postal_code=>"94043", :latitude=>37.41919999999999, :longitude=>-122.0574, :dma_code=>807, :area_code=>650, :timezone=>"America/Los_Angeles"}]
+        end
       end
     end
 
-- 
GitLab