2011-05-08 22:12:01 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class AddressesControllerTest < ActionController::TestCase
|
|
|
|
test 'should return latitude and longitude for a valid address' do
|
2012-11-15 16:56:00 +00:00
|
|
|
stub_request(:get, "http://maps.google.com/maps/geo").
|
2013-12-02 11:37:18 +00:00
|
|
|
with(query: {key: "REPLACE_WITH_YOUR_GOOGLE_KEY", oe: "utf-8", output: "xml", q: "City Hall, Boston, MA"}).
|
2012-06-18 17:49:28 +00:00
|
|
|
to_return(body: File.read(File.expand_path('../../fixtures/city_hall.kml', __FILE__)))
|
2013-12-02 12:07:18 +00:00
|
|
|
get :show, address: 'City Hall', city_state: "Boston, MA", format: 'json'
|
2011-05-08 22:12:01 +00:00
|
|
|
assert_not_nil assigns :address
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should return an error for an invalid address' do
|
2013-10-03 08:52:03 +00:00
|
|
|
stub_request(:get, "http://geocoder.us/service/csv/geocode").
|
2013-12-02 11:37:18 +00:00
|
|
|
with(query: {address: ", "}).
|
2013-10-03 08:52:03 +00:00
|
|
|
to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.txt', __FILE__)))
|
2012-11-15 16:56:00 +00:00
|
|
|
stub_request(:get, "http://maps.google.com/maps/geo").
|
2013-12-02 11:37:18 +00:00
|
|
|
with(query: {key: "REPLACE_WITH_YOUR_GOOGLE_KEY", oe: "utf-8", output: "xml", q: ", "}).
|
2012-06-18 17:49:28 +00:00
|
|
|
to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.kml', __FILE__)))
|
2013-12-02 12:07:18 +00:00
|
|
|
get :show, address: '', city_state: '', format: 'json'
|
2011-05-08 22:12:01 +00:00
|
|
|
assert_response :missing
|
|
|
|
end
|
|
|
|
end
|