diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 8102510b34ccccb3f1c234786d3eacb2d2217d57..6ed7fa62ea24dddf7e4d9ea797ba608b4a9ee408 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -44,7 +44,7 @@ module Geocoder::Lookup params[:region] = region end unless (components = query.options[:components]).nil? - params[:components] = components + params[:components] = components.join("|") end params end diff --git a/test/services_test.rb b/test/services_test.rb index 9174c0c687a6641c7afb17851edb617d28039f4e..6f2a86dd0f33fb56ecebd1ee99e8b73d1a56976f 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -56,6 +56,25 @@ class ServicesTest < Test::Unit::TestCase assert_match /bounds=40.0+%2C-120.0+%7C39.0+%2C-121.0+/, url end + def test_google_query_url_contains_region + lookup = Geocoder::Lookup::Google.new + url = lookup.send(:query_url, Geocoder::Query.new( + "Some Intersection", + :region => "gb" + )) + assert_match /region=gb/, url + end + + def test_google_query_url_contains_properly_formatted_components + lookup = Geocoder::Lookup::Google.new + url = lookup.send(:query_url, Geocoder::Query.new( + "Some Intersection", + :components => ["country:ES", "locality:ES"] + )) + formatted = "components=" + CGI.escape("country:ES|locality:ES") + assert url.include?(formatted), "Expected #{formatted} to be included in #{url}" + end + # --- Google Premier --- def test_google_premier_result_components