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

Don't consider query blank if URL params given.

This allows searching by, for example, WOEID with Yahoo PlaceFinder.
parent ab68be10
No related branches found
No related tags found
No related merge requests found
...@@ -37,10 +37,14 @@ module Geocoder ...@@ -37,10 +37,14 @@ module Geocoder
end end
## ##
# Is the Query text blank? (ie, should we not bother searching?) # Is the Query blank? (ie, should we not bother searching?)
# A query is considered blank if its text is nil or empty string AND
# no URL parameters are specified.
# #
def blank? def blank?
!!text.to_s.match(/^\s*$/) !!text.to_s.match(/^\s*$/) and (
!options[:params].is_a?(Hash) or options[:params].keys.size == 0
)
end end
## ##
......
...@@ -18,6 +18,9 @@ class QueryTest < Test::Unit::TestCase ...@@ -18,6 +18,9 @@ class QueryTest < Test::Unit::TestCase
assert Geocoder::Query.new("\t ").blank? assert Geocoder::Query.new("\t ").blank?
assert !Geocoder::Query.new("a").blank? assert !Geocoder::Query.new("a").blank?
assert !Geocoder::Query.new("Москва").blank? # no ASCII characters assert !Geocoder::Query.new("Москва").blank? # no ASCII characters
assert Geocoder::Query.new(nil, :params => {}).blank?
assert !Geocoder::Query.new(nil, :params => {:woeid => 1234567}).blank?
end end
def test_coordinates_detection def test_coordinates_detection
......
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