Skip to content
Snippets Groups Projects
Commit 037efdf9 authored by Alex Reisner's avatar Alex Reisner
Browse files

Treat coordinates array with nil as a blank query.

This addresses:
https://github.com/alexreisner/geocoder/issues/322
parent 33b89ff0
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,13 @@ module Geocoder ...@@ -40,7 +40,13 @@ module Geocoder
# Is the Query text blank? (ie, should we not bother searching?) # Is the Query text blank? (ie, should we not bother searching?)
# #
def blank? 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 end
## ##
......
...@@ -20,6 +20,11 @@ class QueryTest < Test::Unit::TestCase ...@@ -20,6 +20,11 @@ class QueryTest < Test::Unit::TestCase
assert !Geocoder::Query.new("Москва").blank? # no ASCII characters assert !Geocoder::Query.new("Москва").blank? # no ASCII characters
end 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 def test_coordinates_detection
assert Geocoder::Query.new("51.178844,5").coordinates? assert Geocoder::Query.new("51.178844,5").coordinates?
assert Geocoder::Query.new("51.178844, -1.826189").coordinates? assert Geocoder::Query.new("51.178844, -1.826189").coordinates?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment