Fix geokit

This commit is contained in:
Erik Michaels-Ober 2013-12-03 00:54:40 +01:00
parent 0cfd86ab2d
commit 657502769d
16 changed files with 600 additions and 154 deletions

View File

@ -0,0 +1,19 @@
require 'test_helper'
class AddressesControllerTest < ActionController::TestCase
test 'should return latitude and longitude for a valid address' do
stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
with(:query => {:address => "City Hall, Boston, MA", :sensor => "false"}).
to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
get :show, :address => 'City Hall', :city_state => "Boston, MA", :format => 'json'
assert_not_nil assigns :address
end
test 'should return an error for an invalid address' do
stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
with(:query => {:address => ", ", :sensor => "false"}).
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
get :show, :address => '', :city_state => '', :format => 'json'
assert_response :missing
end
end

View File

@ -9,9 +9,9 @@ class RemindersControllerTest < ActionController::TestCase
@user = users(:erik) @user = users(:erik)
@thing.user = @dan @thing.user = @dan
@thing.save! @thing.save!
stub_request(:get, "http://maps.google.com/maps/geo"). stub_request(:get, "http://maps.google.com/maps/api/geocode/json").
with(:query => {:key => "REPLACE_WITH_YOUR_GOOGLE_KEY", :ll => "42.383339,-71.049226", :oe => "utf-8", :output => "xml"}). with(:query => {:latlng => "42.383339,-71.049226", :sensor => "false"}).
to_return(:body => File.read(File.expand_path('../../fixtures/geo.kml', __FILE__))) to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
end end
test 'should send a reminder email' do test 'should send a reminder email' do

574
test/fixtures/city_hall.json vendored Normal file
View File

@ -0,0 +1,574 @@
{
"results" : [
{
"address_components" : [
{
"long_name" : "Boston City Hall",
"short_name" : "Boston City Hall",
"types" : [ "point_of_interest", "establishment" ]
},
{
"long_name" : "1",
"short_name" : "1",
"types" : [ "street_number" ]
},
{
"long_name" : "City Hall Square",
"short_name" : "City Hall Square",
"types" : [ "route" ]
},
{
"long_name" : "Downtown",
"short_name" : "Downtown",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02201",
"short_name" : "02201",
"types" : [ "postal_code" ]
},
{
"long_name" : "1001",
"short_name" : "1001",
"types" : []
}
],
"formatted_address" : "Boston City Hall, 1 City Hall Square, Boston, MA 02201, USA",
"geometry" : {
"location" : {
"lat" : 42.360406,
"lng" : -71.057993
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.3686503,
"lng" : -71.0419856
},
"southwest" : {
"lat" : 42.3521606,
"lng" : -71.0740004
}
}
},
"partial_match" : true,
"types" : [
"city_hall",
"point_of_interest",
"local_government_office",
"locality",
"political",
"establishment"
]
},
{
"address_components" : [
{
"long_name" : "Faneuil Hall",
"short_name" : "Faneuil Hall",
"types" : [ "point_of_interest", "establishment" ]
},
{
"long_name" : "Boston National Historical Park",
"short_name" : "Boston National Historical Park",
"types" : [ "establishment" ]
},
{
"long_name" : "1",
"short_name" : "1",
"types" : [ "street_number" ]
},
{
"long_name" : "Faneuil Hall Square",
"short_name" : "Faneuil Hall Square",
"types" : [ "route" ]
},
{
"long_name" : "Downtown",
"short_name" : "Downtown",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02109",
"short_name" : "02109",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Faneuil Hall, Boston National Historical Park, 1 Faneuil Hall Square, Boston, MA 02109, USA",
"geometry" : {
"location" : {
"lat" : 42.3600619,
"lng" : -71.05610299999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.36141088029149,
"lng" : -71.05475401970848
},
"southwest" : {
"lat" : 42.3587129197085,
"lng" : -71.0574519802915
}
}
},
"partial_match" : true,
"types" : [ "point_of_interest", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Hall Street",
"short_name" : "Hall St",
"types" : [ "route" ]
},
{
"long_name" : "Jamaica Plain",
"short_name" : "Jamaica Plain",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02130",
"short_name" : "02130",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Hall Street, Boston, MA 02130, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.3054659,
"lng" : -71.1118637
},
"southwest" : {
"lat" : 42.3046598,
"lng" : -71.1146641
}
},
"location" : {
"lat" : 42.3048254,
"lng" : -71.1134469
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 42.3064118302915,
"lng" : -71.1118637
},
"southwest" : {
"lat" : 42.3037138697085,
"lng" : -71.1146641
}
}
},
"partial_match" : true,
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "City Hall Square",
"short_name" : "City Hall Square",
"types" : [ "route" ]
},
{
"long_name" : "Downtown",
"short_name" : "Downtown",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "City Hall Square, Boston, MA, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.360398,
"lng" : -71.05729599999999
},
"southwest" : {
"lat" : 42.3579646,
"lng" : -71.0593976
}
},
"location" : {
"lat" : 42.360248,
"lng" : -71.0574544
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 42.3605302802915,
"lng" : -71.05699781970849
},
"southwest" : {
"lat" : 42.3578323197085,
"lng" : -71.05969578029149
}
}
},
"partial_match" : true,
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "Newhall Street",
"short_name" : "Newhall St",
"types" : [ "route" ]
},
{
"long_name" : "Dorchester",
"short_name" : "Dorchester",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02122",
"short_name" : "02122",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Newhall Street, Boston, MA 02122, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.2893203,
"lng" : -71.050439
},
"southwest" : {
"lat" : 42.2877758,
"lng" : -71.051587
}
},
"location" : {
"lat" : 42.2886742,
"lng" : -71.05117170000001
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 42.2898970302915,
"lng" : -71.04966401970849
},
"southwest" : {
"lat" : 42.2871990697085,
"lng" : -71.05236198029149
}
}
},
"partial_match" : true,
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "City Hall Avenue",
"short_name" : "City Hall Avenue",
"types" : [ "route" ]
},
{
"long_name" : "Downtown",
"short_name" : "Downtown",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "City Hall Avenue, Boston, MA, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.3582279,
"lng" : -71.058887
},
"southwest" : {
"lat" : 42.357693,
"lng" : -71.0593676
}
},
"location" : {
"lat" : 42.358086,
"lng" : -71.05902329999999
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 42.3593094302915,
"lng" : -71.05777831970849
},
"southwest" : {
"lat" : 42.3566114697085,
"lng" : -71.0604762802915
}
}
},
"partial_match" : true,
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "Hall Place",
"short_name" : "Hall Pl",
"types" : [ "route" ]
},
{
"long_name" : "Telegraph Hill",
"short_name" : "Telegraph Hill",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02127",
"short_name" : "02127",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Hall Place, Boston, MA 02127, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.3339539,
"lng" : -71.034485
},
"southwest" : {
"lat" : 42.3335792,
"lng" : -71.0347695
}
},
"location" : {
"lat" : 42.3336703,
"lng" : -71.0347611
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 42.3351155302915,
"lng" : -71.0332782697085
},
"southwest" : {
"lat" : 42.3324175697085,
"lng" : -71.03597623029151
}
}
},
"partial_match" : true,
"types" : [ "route" ]
},
{
"address_components" : [
{
"long_name" : "Hall Avenue",
"short_name" : "Hall Ave",
"types" : [ "route" ]
},
{
"long_name" : "Dudley / Brunswick King",
"short_name" : "Dudley / Brunswick King",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Roxbury",
"short_name" : "Roxbury",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Boston",
"short_name" : "Boston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suffolk",
"short_name" : "Suffolk",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Massachusetts",
"short_name" : "MA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "02121",
"short_name" : "02121",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Hall Avenue, Boston, MA 02121, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.3084888,
"lng" : -71.082103
},
"southwest" : {
"lat" : 42.3082657,
"lng" : -71.0821694
}
},
"location" : {
"lat" : 42.30838,
"lng" : -71.0821347
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 42.3097262302915,
"lng" : -71.0807872197085
},
"southwest" : {
"lat" : 42.3070282697085,
"lng" : -71.0834851802915
}
}
},
"partial_match" : true,
"types" : [ "route" ]
}
],
"status" : "OK"
}

View File

@ -1,48 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>City Hall, Boston, MA</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>Boston City Hall, 1 City Hall Square, Boston, MA 02201-1001, USA</address>
<AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><Locality><LocalityName>Boston</LocalityName><Thoroughfare><ThoroughfareName>Boston City Hall, 1 City Hall Square</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>02201-1001</PostalCodeNumber></PostalCode><AddressLine>Boston City Hall</AddressLine></Locality></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3686503" south="42.3521606" east="-71.0419856" west="-71.0740004" />
</ExtendedData>
<Point><coordinates>-71.0579930,42.3604060,0</coordinates></Point>
</Placemark>
<Placemark id="p2">
<address>State Highway 3, MA, USA</address>
<AddressDetails Accuracy="6" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><Thoroughfare><ThoroughfareName>Massachusetts 3</ThoroughfareName></Thoroughfare></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3363770" south="42.2746700" east="-71.0481820" west="-71.0651655" />
</ExtendedData>
<Point><coordinates>-71.0536709,42.3062860,0</coordinates></Point>
</Placemark>
<Placemark id="p3">
<address>Boston, Massachusetts, USA</address>
<AddressDetails Accuracy="0" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><AddressLine>Boston</AddressLine></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3987970" south="42.2277980" east="-70.9821865" west="-71.1911980" />
</ExtendedData>
<Point><coordinates>-71.0854325,42.3094288,0</coordinates></Point>
</Placemark>
<Placemark id="p4">
<address>Mayor&apos;S-Press Office, 1 City Hall Square, Boston, MA 02201-2013, USA</address>
<AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><Locality><LocalityName>Boston</LocalityName><Thoroughfare><ThoroughfareName>Mayor'S-Press Office, 1 City Hall Square</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>02201-2013</PostalCodeNumber></PostalCode><AddressLine>Mayor'S-Press Office</AddressLine></Locality></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.2985646" south="42.2922694" east="-71.0865872" west="-71.0928824" />
</ExtendedData>
<Point><coordinates>-71.0897348,42.2954170,0</coordinates></Point>
</Placemark>
<Placemark id="p5">
<address>Boston City Hall, Boston, MA 02109, USA</address>
<AddressDetails Accuracy="9" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><Locality><LocalityName>Boston</LocalityName><Thoroughfare><ThoroughfareName>Boston City Hall</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>02109</PostalCodeNumber></PostalCode><AddressLine>Boston City Hall</AddressLine></Locality></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3635641" south="42.3572688" east="-71.0548541" west="-71.0611494" />
</ExtendedData>
<Point><coordinates>-71.0577624,42.3601096,0</coordinates></Point>
</Placemark>
</Response></kml>

72
test/fixtures/geo.kml vendored
View File

@ -1,72 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>42.383339,-71.049226</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>Adamski Memorial Hwy, Boston, MA 02129, USA</address>
<AddressDetails Accuracy="6" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><Locality><LocalityName>Boston</LocalityName><Thoroughfare><ThoroughfareName>Adamski Memorial Hwy</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>02129</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3848890" south="42.3821911" east="-71.0473027" west="-71.0500007" />
</ExtendedData>
<Point><coordinates>-71.0486651,42.3835467,0</coordinates></Point>
</Placemark>
<Placemark id="p2">
<address>Thompson Square / Bunker Hill, Boston, MA, USA</address>
<AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Suffolk</SubAdministrativeAreaName><Locality><LocalityName>Boston</LocalityName><DependentLocality><DependentLocalityName>Thompson Square / Bunker Hill</DependentLocalityName></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3850971" south="42.3694970" east="-71.0474951" west="-71.0725950" />
</ExtendedData>
<Point><coordinates>-71.0646337,42.3747916,0</coordinates></Point>
</Placemark>
<Placemark id="p3">
<address>Charlestown, Boston, MA, USA</address>
<AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Suffolk</SubAdministrativeAreaName><Locality><LocalityName>Boston</LocalityName><DependentLocality><DependentLocalityName>Charlestown</DependentLocalityName></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3906959" south="42.3694970" east="-71.0474951" west="-71.0808960" />
</ExtendedData>
<Point><coordinates>-71.0646337,42.3795409,0</coordinates></Point>
</Placemark>
<Placemark id="p4">
<address>CHARLESTOWN, MA 02129, USA</address>
<AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><Locality><LocalityName>CHARLESTOWN</LocalityName><PostalCode><PostalCodeNumber>02129</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3949960" south="42.3686530" east="-71.0442981" west="-71.0809469" />
</ExtendedData>
<Point><coordinates>-71.0646337,42.3795409,0</coordinates></Point>
</Placemark>
<Placemark id="p5">
<address>Boston, MA, USA</address>
<AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Suffolk</SubAdministrativeAreaName><Locality><LocalityName>Boston</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.3988669" south="42.2278800" east="-70.9232011" west="-71.1911130" />
</ExtendedData>
<Point><coordinates>-71.0597732,42.3584308,0</coordinates></Point>
</Placemark>
<Placemark id="p6">
<address>Suffolk, MA, USA</address>
<AddressDetails Accuracy="3" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Suffolk</SubAdministrativeAreaName></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.4500959" south="42.2278800" east="-70.9232011" west="-71.1911130" />
</ExtendedData>
<Point><coordinates>-71.0504229,42.3522866,0</coordinates></Point>
</Placemark>
<Placemark id="p7">
<address>Massachusetts, USA</address>
<AddressDetails Accuracy="2" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>MA</AdministrativeAreaName></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="42.8867900" south="41.2390737" east="-69.9279921" west="-73.5081419" />
</ExtendedData>
<Point><coordinates>-71.3824374,42.4072107,0</coordinates></Point>
</Placemark>
<Placemark id="p8">
<address>United States</address>
<AddressDetails Accuracy="1" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="49.3800000" south="25.8200000" east="-66.9400000" west="-124.3900000" />
</ExtendedData>
<Point><coordinates>-95.7128910,37.0902400,0</coordinates></Point>
</Placemark>
</Response></kml>

4
test/fixtures/unknown_address.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"results" : [],
"status" : "ZERO_RESULTS"
}

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>, </name>
<Status>
<code>602</code>
<request>geocode</request>
</Status>
</Response></kml>

View File

@ -1 +0,0 @@
2: couldn't find this address! sorry

View File

@ -1,22 +0,0 @@
require 'test_helper'
class AddressesControllerTest < ActionController::TestCase
test 'should return latitude and longitude for a valid address' do
stub_request(:get, "http://maps.google.com/maps/geo").
with(:query => {:key => "REPLACE_WITH_YOUR_GOOGLE_KEY", :oe => "utf-8", :output => "xml", :q => "City Hall, Boston, MA"}).
to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.kml', __FILE__)))
get :show, :address => 'City Hall', :city_state => "Boston, MA", :format => 'json'
assert_not_nil assigns :address
end
test 'should return an error for an invalid address' do
stub_request(:get, "http://geocoder.us/service/csv/geocode").
with(:query => {:address => ", "}).
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.txt', __FILE__)))
stub_request(:get, "http://maps.google.com/maps/geo").
with(:query => {:key => "REPLACE_WITH_YOUR_GOOGLE_KEY", :oe => "utf-8", :output => "xml", :q => ", "}).
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.kml', __FILE__)))
get :show, :address => '', :city_state => '', :format => 'json'
assert_response :missing
end
end