X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/baf9ff0ec39c13f52ee8d4f087641dc5fcc9c53b..fcc68b4dc198b7cb0cf93467d96038b0844675fe:/vendor/plugins/geokit/test/base_geocoder_test.rb diff --git a/vendor/plugins/geokit/test/base_geocoder_test.rb b/vendor/plugins/geokit/test/base_geocoder_test.rb new file mode 100644 index 0000000..b51a739 --- /dev/null +++ b/vendor/plugins/geokit/test/base_geocoder_test.rb @@ -0,0 +1,57 @@ +require 'test/unit' +require 'net/http' +require 'rubygems' +require 'mocha' +require File.join(File.dirname(__FILE__), '../../../../config/environment') + + +class MockSuccess < Net::HTTPSuccess #:nodoc: all + def initialize + end +end + +class MockFailure < Net::HTTPServiceUnavailable #:nodoc: all + def initialize + end +end + +# Base class for testing geocoders. +class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all + + # Defines common test fixtures. + def setup + @address = 'San Francisco, CA' + @full_address = '100 Spear St, San Francisco, CA, 94105-1522, US' + @full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US' + + @success = GeoKit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>37.7742, :lng=>-122.417068}) + @success.success = true + end + + def test_timeout_call_web_service + GeoKit::Geocoders::Geocoder.class_eval do + def self.do_get(url) + sleep(2) + end + end + url = "http://www.anything.com" + GeoKit::Geocoders::timeout = 1 + assert_nil GeoKit::Geocoders::Geocoder.call_geocoder_service(url) + end + + def test_successful_call_web_service + url = "http://www.anything.com" + GeoKit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS") + assert_equal "SUCCESS", GeoKit::Geocoders::Geocoder.call_geocoder_service(url) + end + + def test_find_geocoder_methods + public_methods = GeoKit::Geocoders::Geocoder.public_methods + assert public_methods.include?("yahoo_geocoder") + assert public_methods.include?("google_geocoder") + assert public_methods.include?("ca_geocoder") + assert public_methods.include?("us_geocoder") + assert public_methods.include?("multi_geocoder") + assert public_methods.include?("ip_geocoder") + end +end \ No newline at end of file