]> projects.mako.cc - selectricity-live/blob - vendor/plugins/geokit/test/base_geocoder_test.rb
Merge jdong
[selectricity-live] / vendor / plugins / geokit / test / base_geocoder_test.rb
1 require 'test/unit'
2 require 'net/http'
3 require 'rubygems'
4 require 'mocha'
5 require File.join(File.dirname(__FILE__), '../../../../config/environment')
6
7
8 class MockSuccess < Net::HTTPSuccess #:nodoc: all
9   def initialize
10   end
11 end
12
13 class MockFailure < Net::HTTPServiceUnavailable #:nodoc: all
14   def initialize
15   end
16 end
17
18 # Base class for testing geocoders.
19 class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
20
21   # Defines common test fixtures.
22   def setup
23     @address = 'San Francisco, CA'    
24     @full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'   
25     @full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US' 
26     
27     @success = GeoKit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>37.7742, :lng=>-122.417068})
28     @success.success = true    
29   end  
30   
31   def test_timeout_call_web_service
32     GeoKit::Geocoders::Geocoder.class_eval do
33       def self.do_get(url)
34         sleep(2)
35       end
36     end
37     url = "http://www.anything.com"
38     GeoKit::Geocoders::timeout = 1
39     assert_nil GeoKit::Geocoders::Geocoder.call_geocoder_service(url)    
40   end
41   
42   def test_successful_call_web_service
43     url = "http://www.anything.com"
44     GeoKit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
45     assert_equal "SUCCESS", GeoKit::Geocoders::Geocoder.call_geocoder_service(url)
46   end
47   
48   def test_find_geocoder_methods
49     public_methods = GeoKit::Geocoders::Geocoder.public_methods
50     assert public_methods.include?("yahoo_geocoder")
51     assert public_methods.include?("google_geocoder")
52     assert public_methods.include?("ca_geocoder")
53     assert public_methods.include?("us_geocoder")
54     assert public_methods.include?("multi_geocoder")
55     assert public_methods.include?("ip_geocoder")
56   end
57 end

Benjamin Mako Hill || Want to submit a patch?