Skip to content

Commit

Permalink
Testing Geokit::Geocoders::useragent, Bing geocode fix with options p…
Browse files Browse the repository at this point in the history
…aram, reverse_geocode accepts :provider_order param
  • Loading branch information
Christian Ott authored and mnoack committed Mar 26, 2017
1 parent 5f8428a commit 34b4204
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/geokit/geocoders/bing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.extract_location(xml)
full_address: 'Address/FormattedAddress',
city: 'Address/Locality',
state: 'Address/AdminDistrict',
district: 'Address/AdminDistrict2',
province: 'Address/AdminDistrict2',
zip: 'Address/PostalCode',
country: 'Address/CountryRegion',
lat: 'Point/Latitude',
Expand Down
6 changes: 4 additions & 2 deletions lib/geokit/multi_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def self.do_geocode(address, *args)
# This method will call one or more geocoders in the order specified in
# the configuration until one of the geocoders work, only this time it's
# going to try to reverse geocode a geographical point.
def self.do_reverse_geocode(latlng, *_args)
Geokit::Geocoders.provider_order.each do |provider|
def self.do_reverse_geocode(latlng, *args)
provider_order = provider_order_for(latlng, args)

provider_order.each do |provider|
klass = geocoder(provider)
begin
res = klass.send :reverse_geocode, latlng
Expand Down
46 changes: 46 additions & 0 deletions test/test_useragent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'test/unit'
require 'webmock/test_unit'

require File.join(File.dirname(__FILE__), '../lib/geokit.rb')

class UserAgentTest < Test::Unit::TestCase

NETHTTPDEFAULT = 'Ruby'
NETHTTPDEFAULTHEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}
TYPHOEUSDEFAULT = 'Typhoeus - https://github.com/typhoeus/typhoeus'
TYPHOEUSDEFAULTHEADERS = {'Expect'=>''}
TESTAGENT = 'MyAgent'
URL = 'http://www.example.com'

def test_nethttp_useragent_set_to_testagent
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => TESTAGENT))

Geokit::Geocoders::useragent = TESTAGENT
Geokit::NetAdapter::NetHttp.do_get(URL)
assert_requested :get, URL
end

def test_nethttp_useragent_set_to_default
stub_request(:get, URL).with(:headers => NETHTTPDEFAULTHEADERS.merge('User-Agent' => NETHTTPDEFAULT))

Geokit::Geocoders::useragent = nil
Geokit::NetAdapter::NetHttp.do_get(URL)
assert_requested :get, URL
end

def test_typhoeus_set_to_testagent
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TESTAGENT))

Geokit::Geocoders::useragent = TESTAGENT
Geokit::NetAdapter::Typhoeus.do_get(URL)
assert_requested :get, URL
end

def test_typhoeus_set_to_default
stub_request(:get, URL).with(:headers => TYPHOEUSDEFAULTHEADERS.merge('User-Agent' => TYPHOEUSDEFAULT))

Geokit::Geocoders::useragent = nil
Geokit::NetAdapter::Typhoeus.do_get(URL)
assert_requested :get, URL
end
end

0 comments on commit 34b4204

Please sign in to comment.