public
Description: A Ruby wrapper around the Sunlight Labs API using httparty and happymapper
Homepage:
Clone URL: git://github.com/technicalpickles/daywalker.git
Click here to lend your support to: daywalker and make a donation at www.pledgie.com !
100644 48 lines (40 sloc) 1.336 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
 
module Graticule
  module Geocoder
    class YahooTest < Test::Unit::TestCase
 
      def setup
        URI::HTTP.responses = []
        URI::HTTP.uris = []
        @geocoder = Yahoo.new 'APP_ID'
        @location = Location.new(
          :street => "701 First Ave",
          :locality => "Sunnyvale",
          :region => "CA",
          :postal_code => "94089-1019",
          :country => "US",
          :longitude => -122.024853,
          :latitude => 37.416384,
          :precision => :address
        )
      end
 
    def test_locate
      prepare_response(:success)
      assert_equal @location, @geocoder.locate('701 First Street, Sunnyvale, CA')
    end
  
    def test_url
      prepare_response(:success)
      @geocoder.locate('701 First Street, Sunnyvale, CA')
      assert_equal 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=APP_ID&location=701%20First%20Street,%20Sunnyvale,%20CA&output=xml',
                   URI::HTTP.uris.first
    end
  
 
    def test_locate_bad_address
      prepare_response(:unknown_address)
      assert_raise(Error) { @geocoder.locate('yucksthoeusthaoeusnhtaosu') }
    end
 
    protected
      def prepare_response(id)
        URI::HTTP.responses << response('yahoo', id)
      end
  
    end
  end
end