From 913340cd4a2c5a5414e12ef9c894a5fb07497c67 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 9 Sep 2012 11:40:49 -0400 Subject: [PATCH] Don't consider query blank if URL params given. This allows searching by, for example, WOEID with Yahoo PlaceFinder. --- lib/geocoder/query.rb | 8 ++++++-- test/query_test.rb | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/geocoder/query.rb b/lib/geocoder/query.rb index 3da86ef1..ed438610 100644 --- a/lib/geocoder/query.rb +++ b/lib/geocoder/query.rb @@ -37,10 +37,14 @@ module Geocoder 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? - !!text.to_s.match(/^\s*$/) + !!text.to_s.match(/^\s*$/) and ( + !options[:params].is_a?(Hash) or options[:params].keys.size == 0 + ) end ## diff --git a/test/query_test.rb b/test/query_test.rb index 22a90b5c..ee22e4a9 100644 --- a/test/query_test.rb +++ b/test/query_test.rb @@ -18,6 +18,9 @@ class QueryTest < Test::Unit::TestCase assert Geocoder::Query.new("\t ").blank? assert !Geocoder::Query.new("a").blank? 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 def test_coordinates_detection -- GitLab