Skip to content

Commit

Permalink
Add postal town and get UK test working
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoack committed Dec 12, 2016
1 parent 3903201 commit 688fc47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/geokit/geocoders/google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def self.set_address_components(loc, addr)
when types.include?('administrative_area_level_1') # state
loc.state_code = comp['short_name']
loc.state_name = comp['long_name']
when types.include?('postal_town')
loc.city = comp['long_name']
when types.include?('postal_code')
loc.zip = comp['long_name']
when types.include?('country')
Expand Down
17 changes: 17 additions & 0 deletions test/test_google_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ def test_google_full_address_accuracy
assert_equal 9, res.accuracy
end

def test_google_postal_town
address = 'London SE3 0JB, UK'
url = "#{@base_url}?sensor=false&address=#{escape(address)}"
TestHelper.expects(:last_url).with(url)
res = geocode(address, :google_postal_town)
assert_equal 'Kidbrooke Way', res.street_address
assert_equal 'England', res.state
assert_equal 'London', res.city
assert_equal 'Greater London', res.district
assert_equal 'SE3 0JB', res.zip
assert_equal '51.465923,0.0290915', res.ll
assert !res.is_us?
assert_equal 'Kidbrooke Way, London SE3 0JB, UK', res.full_address
assert_equal 'zip+4', res.precision
assert_equal 'google', res.provider
end

def test_google_city
url = "#{@base_url}?sensor=false&address=#{escape(@address)}"
TestHelper.expects(:last_url).with(url)
Expand Down

0 comments on commit 688fc47

Please sign in to comment.