From 037efdf99c58a1a181c41a2422e207786afecad1 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 23 Oct 2012 18:17:41 -0400 Subject: [PATCH] Treat coordinates array with nil as a blank query. This addresses: https://github.com/alexreisner/geocoder/issues/322 --- lib/geocoder/query.rb | 8 +++++++- test/query_test.rb | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/query.rb b/lib/geocoder/query.rb index 3da86ef1..d4d93b1a 100644 --- a/lib/geocoder/query.rb +++ b/lib/geocoder/query.rb @@ -40,7 +40,13 @@ module Geocoder # Is the Query text blank? (ie, should we not bother searching?) # def blank? - !!text.to_s.match(/^\s*$/) + # check whether both coordinates given + if text.is_a?(Array) + text.compact.size < 2 + # else assume a string + else + !!text.to_s.match(/^\s*$/) + end end ## diff --git a/test/query_test.rb b/test/query_test.rb index 22a90b5c..fada72ad 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -20,6 +20,11 @@ class QueryTest < Test::Unit::TestCase assert !Geocoder::Query.new("МоÑква").blank? # no ASCII characters end + def test_blank_query_detection_for_coordinates + assert Geocoder::Query.new([nil,nil]).blank? + assert Geocoder::Query.new([87,nil]).blank? + end + def test_coordinates_detection assert Geocoder::Query.new("51.178844,5").coordinates? assert Geocoder::Query.new("51.178844, -1.826189").coordinates? -- GitLab