2013-12-02 23:54:40 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class AddressesControllerTest < ActionController::TestCase
|
|
|
|
test 'should return latitude and longitude for a valid address' do
|
2014-04-01 08:15:29 +00:00
|
|
|
stub_request(:get, 'http://maps.google.com/maps/api/geocode/json').
|
|
|
|
with(query: {address: 'City Hall, Boston, MA', sensor: 'false'}).
|
2014-03-25 09:47:44 +00:00
|
|
|
to_return(body: File.read(File.expand_path('../../fixtures/city_hall.json', __FILE__)))
|
2014-04-01 08:15:29 +00:00
|
|
|
get :show, address: 'City Hall', city_state: 'Boston, MA', format: 'json'
|
2013-12-02 23:54:40 +00:00
|
|
|
assert_not_nil assigns :address
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should return an error for an invalid address' do
|
2014-04-01 08:15:29 +00:00
|
|
|
stub_request(:get, 'http://maps.google.com/maps/api/geocode/json').
|
|
|
|
with(query: {address: ', ', sensor: 'false'}).
|
2014-03-25 09:47:44 +00:00
|
|
|
to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
|
2014-04-01 08:15:29 +00:00
|
|
|
stub_request(:get, 'http://geocoder.us/service/csv/geocode').
|
|
|
|
with(query: {address: ', '}).
|
2014-03-25 09:47:44 +00:00
|
|
|
to_return(body: File.read(File.expand_path('../../fixtures/unknown_address.json', __FILE__)))
|
|
|
|
get :show, address: '', city_state: '', format: 'json'
|
2013-12-02 23:54:40 +00:00
|
|
|
assert_response :missing
|
|
|
|
end
|
|
|
|
end
|