Skip to content
Browse files

Force utf-8 encoding on location initialize.

  • Loading branch information...
1 parent 20ddf06 commit a8206fbc93400262d2b7d8378ce56edefd8c311a @bryckbost bryckbost committed Aug 4, 2011
Showing with 36 additions and 4 deletions.
  1. +1 −1 lib/graticule/location.rb
  2. +16 −0 test/fixtures/responses/google/encoding.xml
  3. +19 −3 test/graticule/geocoder/google_test.rb
View
2 lib/graticule/location.rb
@@ -10,7 +10,7 @@ class Location
def initialize(attrs = {})
attrs.each do |key,value|
- self.send("#{key}=", value)
+ self.send("#{key}=", value.is_a?(String) ? value.force_encoding('UTF-8') : value)
end
self.precision ||= :unknown
end
View
16 test/fixtures/responses/google/encoding.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<kml xmlns="http://earth.google.com/kml/2.0"><Response>
+ <name>Rämistrasse 4, 8001 Zürich, Switzerland</name>
+ <Status>
+ <code>200</code>
+ <request>geocode</request>
+ </Status>
+ <Placemark id="p1">
+ <address>Rämistrasse 4, 8001 Zurich, Switzerland</address>
+ <AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CH</CountryNameCode><CountryName>Schweiz</CountryName><AdministrativeArea><AdministrativeAreaName>Zürich</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Zürich</SubAdministrativeAreaName><Locality><LocalityName>Zürich</LocalityName><DependentLocality><DependentLocalityName>Kreis 1</DependentLocalityName><Thoroughfare><ThoroughfareName>Rämistrasse 4</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>8001</PostalCodeNumber></PostalCode></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
+ <ExtendedData>
+ <LatLonBox north="47.3689701" south="47.3662721" east="8.5470676" west="8.5443696" />
+ </ExtendedData>
+ <Point><coordinates>8.5457186,47.3676211,0</coordinates></Point>
+ </Placemark>
+</Response></kml>
View
22 test/graticule/geocoder/google_test.rb
@@ -25,9 +25,25 @@ def test_success
)
assert_equal location, @geocoder.locate('1600 Amphitheatre Parkway, Mountain View, CA')
end
-
- # The #locate parameters are broad, so the XML response contains
- # multiple results at street-level precision. We expect to get the
+
+ def test_encoding
+ return unless prepare_response(:encoding)
+
+ location = Location.new(
+ :street => "Rämistrasse 4",
+ :locality => "Zürich",
+ :region=>"Zürich",
+ :postal_code => "8001",
+ :country => "CH",
+ :longitude => 8.5457186,
+ :latitude => 47.3676211,
+ :precision => 'address'
+ )
+ assert_equal location.attributes, @geocoder.locate('Rämistrasse 4, 8001 Zürich, Switzerland').attributes
+ end
+
+ # The #locate parameters are broad, so the XML response contains
+ # multiple results at street-level precision. We expect to get the
# first result back, and it should not contain a postal code.
def test_success_multiple_results
return unless prepare_response(:success_multiple_results)

0 comments on commit a8206fb

Please sign in to comment.
Something went wrong with that request. Please try again.