]> projects.mako.cc - selectricity/blob - vendor/plugins/geokit/test/ca_geocoder_test.rb
referenced mailing list and gitorious
[selectricity] / vendor / plugins / geokit / test / ca_geocoder_test.rb
1 require File.join(File.dirname(__FILE__), 'base_geocoder_test')
2
3 GeoKit::Geocoders::geocoder_ca = "SOMEKEYVALUE"
4
5 class CaGeocoderTest < BaseGeocoderTest #:nodoc: all
6   
7   CA_SUCCESS=<<-EOF
8   <?xml version="1.0" encoding="UTF-8" ?>
9   <geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>  
10   EOF
11   
12   def setup
13     @ca_full_hash = {:street_address=>"2105 West 32nd Avenue",:city=>"Vancouver", :state=>"BC"}
14     @ca_full_loc = GeoKit::GeoLoc.new(@ca_full_hash)
15   end  
16   
17   def test_geocoder_with_geo_loc_with_account
18     response = MockSuccess.new
19     response.expects(:body).returns(CA_SUCCESS)
20     url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
21     GeoKit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
22     verify(GeoKit::Geocoders::CaGeocoder.geocode(@ca_full_loc))    
23   end
24   
25   def test_service_unavailable
26     response = MockFailure.new
27     #Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)  
28     url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml" 
29     GeoKit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
30     assert !GeoKit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success   
31   end  
32   
33   private
34   
35   def verify(location)
36     assert_equal "BC", location.state
37     assert_equal "Vancouver", location.city 
38     assert_equal "49.243086,-123.153684", location.ll 
39     assert !location.is_us? 
40   end
41 end

Benjamin Mako Hill || Want to submit a patch?