geokit 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +13 -0
  4. data/CHANGELOG.md +92 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +25 -0
  7. data/Manifest.txt +21 -0
  8. data/README.markdown +179 -176
  9. data/Rakefile +8 -1
  10. data/ext/mkrf_conf.rb +15 -0
  11. data/geokit.gemspec +33 -0
  12. data/lib/geokit/geocoders.rb +7 -774
  13. data/lib/geokit/inflectors.rb +38 -0
  14. data/lib/geokit/mappable.rb +61 -3
  15. data/lib/geokit/multi_geocoder.rb +61 -0
  16. data/lib/geokit/services/ca_geocoder.rb +55 -0
  17. data/lib/geokit/services/fcc.rb +57 -0
  18. data/lib/geokit/services/geo_plugin.rb +31 -0
  19. data/lib/geokit/services/geonames.rb +53 -0
  20. data/lib/geokit/services/google.rb +158 -0
  21. data/lib/geokit/services/google3.rb +202 -0
  22. data/lib/geokit/services/ip.rb +103 -0
  23. data/lib/geokit/services/openstreetmap.rb +119 -0
  24. data/lib/geokit/services/us_geocoder.rb +50 -0
  25. data/lib/geokit/services/yahoo.rb +75 -0
  26. data/lib/geokit/version.rb +3 -0
  27. data/test/helper.rb +92 -0
  28. data/test/test_base_geocoder.rb +1 -15
  29. data/test/test_bounds.rb +1 -2
  30. data/test/test_ca_geocoder.rb +1 -1
  31. data/test/test_geoloc.rb +35 -5
  32. data/test/test_geoplugin_geocoder.rb +1 -2
  33. data/test/test_google_geocoder.rb +39 -2
  34. data/test/test_google_geocoder3.rb +55 -3
  35. data/test/test_google_reverse_geocoder.rb +1 -1
  36. data/test/test_inflector.rb +5 -3
  37. data/test/test_ipgeocoder.rb +25 -1
  38. data/test/test_latlng.rb +1 -3
  39. data/test/test_multi_geocoder.rb +1 -1
  40. data/test/test_multi_ip_geocoder.rb +1 -1
  41. data/test/test_openstreetmap_geocoder.rb +161 -0
  42. data/test/test_polygon_contains.rb +101 -0
  43. data/test/test_us_geocoder.rb +1 -1
  44. data/test/test_yahoo_geocoder.rb +18 -1
  45. metadata +164 -83
@@ -0,0 +1,75 @@
1
+ module Geokit
2
+ module Geocoders
3
+ # Yahoo geocoder implementation. Requires the Geokit::Geocoders::YAHOO variable to
4
+ # contain a Yahoo API key. Conforms to the interface set by the Geocoder class.
5
+ class YahooGeocoder < Geocoder
6
+
7
+ private
8
+
9
+ # Template method which does the geocode lookup.
10
+ def self.do_geocode(address, options = {})
11
+ address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address
12
+ url="http://where.yahooapis.com/geocode?flags=J&appid=#{Geokit::Geocoders::yahoo}&q=#{Geokit::Inflector::url_escape(address_str)}"
13
+ res = self.call_geocoder_service(url)
14
+ return GeoLoc.new if !res.is_a?(Net::HTTPSuccess)
15
+ json = res.body
16
+ logger.debug "Yahoo geocoding. Address: #{address}. Result: #{json}"
17
+ return self.json2GeoLoc(json, address)
18
+ end
19
+
20
+ def self.json2GeoLoc(json, address)
21
+ results = MultiJson.load(json)
22
+
23
+ if results['ResultSet']['Error'] == 0 && results['ResultSet']['Results'] != nil && results['ResultSet']['Results'].first != nil
24
+ geoloc = nil
25
+ results['ResultSet']['Results'].each do |result|
26
+ extracted_geoloc = extract_geoloc(result)
27
+ if geoloc.nil?
28
+ geoloc = extracted_geoloc
29
+ else
30
+ geoloc.all.push(extracted_geoloc)
31
+ end
32
+ end
33
+ return geoloc
34
+ else
35
+ logger.info "Yahoo was unable to geocode address: " + address
36
+ return GeoLoc.new
37
+ end
38
+ end
39
+
40
+ def self.extract_geoloc(result_json)
41
+ geoloc = GeoLoc.new
42
+
43
+ # basic
44
+ geoloc.lat = result_json['latitude']
45
+ geoloc.lng = result_json['longitude']
46
+ geoloc.country_code = result_json['countrycode']
47
+ geoloc.provider = 'yahoo'
48
+
49
+ # extended
50
+ geoloc.street_address = result_json['line1'].to_s.empty? ? nil : result_json['line1']
51
+ geoloc.city = result_json['city']
52
+ geoloc.state = geoloc.is_us? ? result_json['statecode'] : result_json['state']
53
+ geoloc.zip = result_json['postal']
54
+
55
+ geoloc.precision = case result_json['quality']
56
+ when 9,10 then 'country'
57
+ when 19..30 then 'state'
58
+ when 39,40 then 'city'
59
+ when 49,50 then 'neighborhood'
60
+ when 59,60,64 then 'zip'
61
+ when 74,75 then 'zip+4'
62
+ when 70..72 then 'street'
63
+ when 80..87 then 'address'
64
+ when 62,63,90,99 then 'building'
65
+ else 'unknown'
66
+ end
67
+
68
+ geoloc.accuracy = %w{unknown country state state city zip zip+4 street address building}.index(geoloc.precision)
69
+ geoloc.success = true
70
+
71
+ return geoloc
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module Geokit
2
+ VERSION = '1.6.6'
3
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+
3
+ begin
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ Bundler.setup
7
+ rescue LoadError => e
8
+ puts "Error loading bundler (#{e.message}): \"gem install bundler\" for bundler support."
9
+ end
10
+
11
+ if ENV['COVERAGE']
12
+ COVERAGE_THRESHOLD = 84
13
+ require 'simplecov'
14
+ require 'simplecov-rcov'
15
+ require 'coveralls'
16
+ Coveralls.wear!
17
+
18
+ SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
19
+ SimpleCov.start do
20
+ add_filter '/test/'
21
+ add_group 'lib', 'lib'
22
+ end
23
+ SimpleCov.at_exit do
24
+ SimpleCov.result.format!
25
+ percent = SimpleCov.result.covered_percent
26
+ unless percent >= COVERAGE_THRESHOLD
27
+ puts "Coverage must be above #{COVERAGE_THRESHOLD}%. It is #{"%.2f" % percent}%"
28
+ Kernel.exit(1)
29
+ end
30
+ end
31
+ end
32
+
33
+ require 'test/unit'
34
+ require 'mocha/setup'
35
+ require 'net/http'
36
+
37
+ require File.join(File.dirname(__FILE__), "../lib/geokit.rb")
38
+
39
+ class MockSuccess < Net::HTTPSuccess #:nodoc: all
40
+ def initialize
41
+ @header = {}
42
+ end
43
+ end
44
+
45
+ class MockFailure < Net::HTTPServiceUnavailable #:nodoc: all
46
+ def initialize
47
+ @header = {}
48
+ end
49
+ end
50
+
51
+ # Base class for testing geocoders.
52
+ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
53
+
54
+ class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
55
+ def self.do_get(url)
56
+ sleep(2)
57
+ end
58
+ end
59
+
60
+ # Defines common test fixtures.
61
+ def setup
62
+ @address = 'San Francisco, CA'
63
+ @full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
64
+ @full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
65
+
66
+ @latlng = Geokit::LatLng.new(37.7742, -122.417068)
67
+ @success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>@latlng.lat, :lng=>@latlng.lng})
68
+ @success.success = true
69
+ end
70
+
71
+ def test_timeout_call_web_service
72
+ url = "http://www.anything.com"
73
+ Geokit::Geocoders::request_timeout = 1
74
+ assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
75
+ end
76
+
77
+ def test_successful_call_web_service
78
+ url = "http://www.anything.com"
79
+ Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
80
+ assert_equal "SUCCESS", Geokit::Geocoders::Geocoder.call_geocoder_service(url)
81
+ end
82
+
83
+ def test_find_geocoder_methods
84
+ public_methods = Geokit::Geocoders::Geocoder.public_methods.map { |m| m.to_s }
85
+ assert public_methods.include?("yahoo_geocoder")
86
+ assert public_methods.include?("google_geocoder")
87
+ assert public_methods.include?("ca_geocoder")
88
+ assert public_methods.include?("us_geocoder")
89
+ assert public_methods.include?("multi_geocoder")
90
+ assert public_methods.include?("ip_geocoder")
91
+ end
92
+ end
@@ -1,18 +1,4 @@
1
- require 'test/unit'
2
- require 'net/http'
3
- require 'rubygems'
4
- require 'mocha'
5
- require 'lib/geokit'
6
-
7
- class MockSuccess < Net::HTTPSuccess #:nodoc: all
8
- def initialize
9
- end
10
- end
11
-
12
- class MockFailure < Net::HTTPServiceUnavailable #:nodoc: all
13
- def initialize
14
- end
15
- end
1
+ require File.join(File.dirname(__FILE__), 'helper')
16
2
 
17
3
  # Base class for testing geocoders.
18
4
  class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'lib/geokit'
1
+ require File.join(File.dirname(__FILE__), 'helper')
3
2
 
4
3
  class BoundsTest < Test::Unit::TestCase #:nodoc: all
5
4
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  Geokit::Geocoders::geocoder_ca = "SOMEKEYVALUE"
4
4
 
@@ -1,5 +1,4 @@
1
- require 'test/unit'
2
- require 'lib/geokit'
1
+ require File.join(File.dirname(__FILE__), 'helper')
3
2
 
4
3
  class GeoLocTest < Test::Unit::TestCase #:nodoc: all
5
4
 
@@ -64,9 +63,40 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
64
63
  @loc.state = 'CA'
65
64
  @loc.zip = '94105'
66
65
  @loc.country_code = 'US'
67
- assert_equal(
68
- "--- !ruby/object:Geokit::GeoLoc \ncity: San Francisco\ncountry_code: US\nfull_address: \nlat: \nlng: \nprecision: unknown\nprovince: \nstate: CA\nstreet_address: \nstreet_name: \nstreet_number: \nsub_premise: \nsuccess: false\nzip: \"94105\"\n",
69
- @loc.to_yaml)
66
+
67
+ yaml = YAML::parse(@loc.to_yaml)
68
+ case yaml.class.to_s
69
+ when 'YAML::Syck::Map', 'Syck::Map'
70
+ tag = yaml.type_id
71
+ children = yaml.value.sort_by{|k, v| k.value}.flatten.map(&:value)
72
+ when 'Psych::Nodes::Mapping'
73
+ tag = yaml.tag
74
+ children = yaml.children.map(&:value)
75
+ when 'Psych::Nodes::Document'
76
+ tag = yaml.root.tag
77
+ children = yaml.root.children.map(&:value)
78
+ end
79
+ assert_match /.*object:Geokit::GeoLoc$/, tag
80
+ assert_equal [
81
+ 'city', 'San Francisco',
82
+ 'country_code', 'US',
83
+ 'full_address', '',
84
+ 'lat', '',
85
+ 'lng', '',
86
+ 'precision', 'unknown',
87
+ 'province', '',
88
+ 'state', 'CA',
89
+ 'street_address', '',
90
+ 'street_name', '',
91
+ 'street_number', '',
92
+ 'sub_premise', '',
93
+ 'success', 'false',
94
+ 'zip', '94105'
95
+ ], children
70
96
  end
71
97
 
98
+ def test_neighborhood
99
+ @loc.neighborhood = "SoMa"
100
+ assert_equal @loc.neighborhood, 'SoMa'
101
+ end
72
102
  end
@@ -1,5 +1,4 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
3
2
 
4
3
  class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
5
4
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ # encoding: UTF-8
2
+ require File.join(File.dirname(__FILE__), 'helper')
2
3
 
3
4
  Geokit::Geocoders::google = 'Google'
4
5
 
@@ -31,6 +32,25 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
31
32
  GOOGLE_TOO_MANY=<<-EOF.strip
32
33
  <?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>100 spear st, san francisco, ca</name><Status><code>620</code><request>geocode</request></Status></Response></kml>
33
34
  EOF
35
+
36
+ GOOGLE_UTF8_RESULT=<<-EOF
37
+ <?xml version="1.0" encoding="UTF-8" ?>
38
+ <kml xmlns="http://earth.google.com/kml/2.0"><Response>
39
+ <name>Mosjøen, Norway</name>
40
+ <Status>
41
+ <code>200</code>
42
+ <request>geocode</request>
43
+ </Status>
44
+ <Placemark id="p1">
45
+ <address>Mosjøen, Norway</address>
46
+ <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>NO</CountryNameCode><CountryName>Norge</CountryName><AdministrativeArea><AdministrativeAreaName>Nordland</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Vefsn</SubAdministrativeAreaName><Locality><LocalityName>Mosjøen</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
47
+ <ExtendedData>
48
+ <LatLonBox north="65.8551869" south="65.8186481" east="13.2574307" west="13.1293713" />
49
+ </ExtendedData>
50
+ <Point><coordinates>13.1934010,65.8369240,0</coordinates></Point>
51
+ </Placemark>
52
+ </Response></kml>
53
+ EOF
34
54
 
35
55
  def setup
36
56
  super
@@ -39,6 +59,8 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
39
59
 
40
60
  @google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
41
61
  @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
62
+
63
+ @address_with_special_characters = "Mosjøen, Norway"
42
64
  end
43
65
 
44
66
  def test_google_full_address
@@ -205,7 +227,7 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
205
227
  response = MockSuccess.new
206
228
  response.expects(:body).returns(GOOGLE_BOUNDS_BIASED_RESULT)
207
229
 
208
- url = "http://maps.google.com/maps/geo?q=Winnetka&output=xml&ll=34.197693208849,-118.547160027785&spn=0.247047999999999,0.294914000000006&key=Google&oe=utf-8"
230
+ url = "http://maps.google.com/maps/geo?q=Winnetka&output=xml&ll=34.197693,-118.547160&spn=0.247048,0.294914&key=Google&oe=utf-8"
209
231
  Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
210
232
 
211
233
  bounds = Geokit::Bounds.normalize([34.074081, -118.694401], [34.321129, -118.399487])
@@ -224,4 +246,19 @@ class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
224
246
  res=Geokit::Geocoders::GoogleGeocoder.geocode(@address)
225
247
  end
226
248
  end
249
+
250
+ def test_utf8_encoding
251
+ response = MockSuccess.new
252
+ body = GOOGLE_UTF8_RESULT
253
+ body = body.force_encoding('ASCII-8BIT') if body.respond_to? :force_encoding
254
+ response.expects(:body).returns(body)
255
+ url = "http://maps.google.com/maps/geo?q=#{Geokit::Inflector.url_escape(@address_with_special_characters)}&output=xml&key=Google&oe=utf-8"
256
+ Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
257
+ res=Geokit::Geocoders::GoogleGeocoder.geocode(@address_with_special_characters)
258
+ assert_equal "Nordland", res.state
259
+ assert_equal "Mosjøen", res.city
260
+ assert_equal "65.836924,13.193401", res.ll
261
+ assert !res.is_us?
262
+ assert_equal "google", res.provider
263
+ end
227
264
  end
@@ -1,6 +1,10 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  Geokit::Geocoders::google = 'Google'
4
+ Geokit::Geocoders::google_client_id = nil
5
+ Geokit::Geocoders::google_cryptographic_key = nil
6
+ Geokit::Geocoders::google_channel = nil
7
+
4
8
 
5
9
  class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
6
10
 
@@ -372,6 +376,12 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
372
376
  "status": "OVER_QUERY_LIMIT"
373
377
  }
374
378
  /
379
+ GOOGLE3_INVALID_REQUEST=%q/
380
+ {
381
+ "results" : [],
382
+ "status" : "INVALID_REQUEST"
383
+ }
384
+ /
375
385
  def setup
376
386
  super
377
387
  @full_address = '100 Spear St Apt. 5, San Francisco, CA, 94105-1522, US'
@@ -383,6 +393,29 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
383
393
  @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
384
394
  end
385
395
 
396
+
397
+ # Example from:
398
+ # https://developers.google.com/maps/documentation/business/webservices#signature_examples
399
+ def test_google3_signature
400
+ cryptographic_key = 'vNIXE0xscrmjlyV-12Nj_BvUPaw='
401
+ query_string = '/maps/api/geocode/json?address=New+York&sensor=false&client=clientID'
402
+ signature = Geokit::Geocoders::GoogleGeocoder3.send(:sign_gmap_bus_api_url, query_string, cryptographic_key)
403
+ assert_equal 'KrU1TzVQM7Ur0i8i7K3huiw3MsA=', signature
404
+ end
405
+
406
+
407
+ # Example from:
408
+ # https://developers.google.com/maps/documentation/business/webservices#signature_examples
409
+ def test_google3_signature_and_url
410
+ Geokit::Geocoders::google_client_id = 'clientID'
411
+ Geokit::Geocoders::google_cryptographic_key = 'vNIXE0xscrmjlyV-12Nj_BvUPaw='
412
+ url = Geokit::Geocoders::GoogleGeocoder3.send(:submit_url, '/maps/api/geocode/json?address=New+York&sensor=false')
413
+ Geokit::Geocoders::google_client_id = nil
414
+ Geokit::Geocoders::google_cryptographic_key = nil
415
+ assert_equal 'http://maps.googleapis.com/maps/api/geocode/json?address=New+York&sensor=false&client=clientID&signature=KrU1TzVQM7Ur0i8i7K3huiw3MsA=', url
416
+ end
417
+
418
+
386
419
  def test_google3_full_address
387
420
  response = MockSuccess.new
388
421
  response.expects(:body).returns(GOOGLE3_FULL)
@@ -418,7 +451,6 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
418
451
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
419
452
  res=Geokit::Geocoders::GoogleGeocoder3.geocode(@google_full_loc)
420
453
 
421
- puts res.to_hash.inspect
422
454
  assert_equal 9, res.accuracy
423
455
  end
424
456
 
@@ -469,9 +501,19 @@ puts res.to_hash.inspect
469
501
  res = Geokit::Geocoders::GoogleGeocoder3.geocode(@google_full_loc)
470
502
 
471
503
  assert_instance_of Geokit::Bounds, res.suggested_bounds
472
- assert_equal Geokit::Bounds.new(Geokit::LatLng.new(37.7908019197085, -122.395348980292), Geokit::LatLng.new(37.7934998802915, -122.392651019708)), res.suggested_bounds
504
+ assert_equal Geokit::Bounds.new(Geokit::LatLng.new(37.7908019197085, -122.3953489802915), Geokit::LatLng.new(37.7934998802915, -122.3926510197085)), res.suggested_bounds
473
505
  end
474
506
 
507
+ def test_google3_suggested_bounds_url
508
+ bounds = Geokit::Bounds.new(
509
+ Geokit::LatLng.new(33.7036917, -118.6681759),
510
+ Geokit::LatLng.new(34.3373061, -118.1552891)
511
+ )
512
+ url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=Winnetka&bounds=33.7036917%2C-118.6681759%7C34.3373061%2C-118.1552891"
513
+ Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url)
514
+ Geokit::Geocoders::GoogleGeocoder3.geocode('Winnetka', :bias => bounds)
515
+ end
516
+
475
517
  def test_service_unavailable
476
518
  response = MockFailure.new
477
519
  url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
@@ -554,4 +596,14 @@ puts res.to_hash.inspect
554
596
  res=Geokit::Geocoders::GoogleGeocoder3.geocode(@address)
555
597
  end
556
598
  end
599
+
600
+ def test_invalid_request
601
+ response = MockSuccess.new
602
+ response.expects(:body).returns(GOOGLE3_INVALID_REQUEST)
603
+ url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector.url_escape("3961 V\u00EDa Marisol")}"
604
+ Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
605
+ assert_raise Geokit::Geocoders::GeocodeError do
606
+ Geokit::Geocoders::GoogleGeocoder3.geocode("3961 V\u00EDa Marisol")
607
+ end
608
+ end
557
609
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  Geokit::Geocoders::google = 'Google'
4
4
 
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
-
3
- require 'test/unit'
4
- require 'lib/geokit'
2
+ require File.join(File.dirname(__FILE__), 'helper')
5
3
 
6
4
  class InflectorTest < Test::Unit::TestCase #:nodoc: all
7
5
 
@@ -21,4 +19,8 @@ class InflectorTest < Test::Unit::TestCase #:nodoc: all
21
19
  assert_equal 'Borås (Abc)', Geokit::Inflector.titleize('borås (abc)')
22
20
  end
23
21
 
22
+ def test_url_escape
23
+ assert_equal '%E4%B8%8A%E6%B5%B7%E5%B8%82%E5%BE%90%E6%B1%87%E5%8C%BA%E6%BC%95%E6%BA%AA%E5%8C%97%E8%B7%AF1111%E5%8F%B7', GeoKit::Inflector.url_escape('上海市徐汇区漕溪北路1111号')
24
+ assert_equal '%C3%BC%C3%B6%C3%A4', Geokit::Inflector.url_escape('üöä')
25
+ end
24
26
  end