Add tests for address controller
This commit is contained in:
parent
bf382a4213
commit
d2a785c381
1
Gemfile
1
Gemfile
|
@ -15,6 +15,7 @@ end
|
|||
group :test do
|
||||
gem 'simplecov'
|
||||
gem 'turn', :require => false
|
||||
gem 'webmock'
|
||||
end
|
||||
|
||||
group :production do
|
||||
|
|
|
@ -31,6 +31,7 @@ GEM
|
|||
activesupport (= 3.1.0.beta1)
|
||||
activesupport (3.1.0.beta1)
|
||||
multi_json (~> 1.0)
|
||||
addressable (2.2.5)
|
||||
ansi (1.2.5)
|
||||
arel (2.1.0)
|
||||
bcrypt-ruby (2.1.4)
|
||||
|
@ -41,6 +42,7 @@ GEM
|
|||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.1.0)
|
||||
crack (0.1.8)
|
||||
devise (1.3.4)
|
||||
bcrypt-ruby (~> 2.1.2)
|
||||
orm_adapter (~> 0.0.3)
|
||||
|
@ -105,6 +107,9 @@ GEM
|
|||
tzinfo (0.3.27)
|
||||
warden (1.0.4)
|
||||
rack (>= 1.0)
|
||||
webmock (1.6.2)
|
||||
addressable (>= 2.2.2)
|
||||
crack (>= 0.1.7)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
|
@ -122,3 +127,4 @@ DEPENDENCIES
|
|||
simplecov
|
||||
therubyracer-heroku (= 0.8.1.pre3)
|
||||
turn
|
||||
webmock
|
||||
|
|
|
@ -6,7 +6,7 @@ class AddressesController < ApplicationController
|
|||
unless @address.blank?
|
||||
respond_with @address
|
||||
else
|
||||
render(:json => {"errors" => {"address" => ["Could not find address."]}})
|
||||
render(:json => {"errors" => {"address" => ["Could not find address."]}}, :status => 404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
require File.expand_path('../boot', __FILE__)
|
||||
|
||||
require 'rails/all'
|
||||
require "active_record/railtie"
|
||||
require "action_controller/railtie"
|
||||
require "action_mailer/railtie"
|
||||
require "rails/test_unit/railtie"
|
||||
|
||||
# If you have a Gemfile, require the gems listed there, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?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'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>
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +0,0 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
|
@ -0,0 +1,8 @@
|
|||
<?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>
|
|
@ -1,11 +0,0 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
one: {}
|
||||
# column: value
|
||||
#
|
||||
two: {}
|
||||
# column: value
|
|
@ -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/geo?q=City+Hall%2C+Boston%2C+MA&output=xml&key=REPLACE_WITH_YOUR_GOOGLE_KEY&oe=utf-8').
|
||||
to_return(:body => File.read(File.expand_path('../../fixtures/city_hall.kml', __FILE__)), :status => 200)
|
||||
get :show, :address => 'City Hall', :city_state => "Boston, MA"
|
||||
assert_not_nil assigns :address
|
||||
end
|
||||
|
||||
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').
|
||||
to_return(:body => File.read(File.expand_path('../../fixtures/unknown_address.kml', __FILE__)), :status => 200)
|
||||
stub_request(:get, 'http://geocoder.us/service/csv/geocode?address=%2C+').
|
||||
to_return(:body => '', :status => 204)
|
||||
get :show, :address => '', :city_state => ''
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
|
@ -3,6 +3,7 @@ SimpleCov.start 'rails'
|
|||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path('../../config/environment', __FILE__)
|
||||
require 'rails/test_help'
|
||||
require 'webmock/test_unit'
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class UsersHelperTest < ActionView::TestCase
|
||||
end
|
|
@ -1,4 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class WelcomeHelperTest < ActionView::TestCase
|
||||
end
|
Loading…
Reference in New Issue