Add new fixtures to tests

This commit is contained in:
Erik Michaels-Ober 2012-11-15 08:56:00 -08:00
parent cceb2b1b55
commit fe88a0fafb
4 changed files with 80 additions and 5 deletions

72
test/fixtures/geo.kml vendored Normal file
View File

@ -0,0 +1,72 @@
<?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>

View File

@ -2,17 +2,17 @@ require 'test_helper'
class AddressesControllerTest < ActionController::TestCase class AddressesControllerTest < ActionController::TestCase
test 'should return latitude and longitude for a valid address' do test 'should return latitude and longitude for a valid address' do
stub_request(:get, 'http://maps.google.com/maps/geo?q=City+Hall%2C+Boston%2C+MA&output=xml&key=REPLACE_WITH_YOUR_GOOGLE_KEY&oe=utf-8'). 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__))) to_return(body: File.read(File.expand_path('../../fixtures/city_hall.kml', __FILE__)))
get :show, address: 'City Hall', city_state: "Boston, MA" get :show, address: 'City Hall', city_state: "Boston, MA"
assert_not_nil assigns :address assert_not_nil assigns :address
end end
test 'should return an error for an invalid address' do test 'should return an error for an invalid address' do
stub_request(:get, 'http://maps.google.com/maps/geo?q=%2C+&output=xml&key=REPLACE_WITH_YOUR_GOOGLE_KEY&oe=utf-8'). 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__))) to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.kml', __FILE__)))
stub_request(:get, 'http://geocoder.us/service/csv/geocode?address=%2C+').
to_return(body: '', status: 204)
get :show, address: '', city_state: '' get :show, address: '', city_state: ''
assert_response :missing assert_response :missing
end end

View File

@ -9,6 +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").
with(:query => {:key => "REPLACE_WITH_YOUR_GOOGLE_KEY", :ll => "42.383339,-71.049226", :oe => "utf-8", :output => "xml"}).
to_return(body: File.read(File.expand_path('../../fixtures/geo.kml', __FILE__)))
end end
test 'should send a reminder email' do test 'should send a reminder email' do