Skip to content

Commit

Permalink
Fixing hash bug. Adding GeoLoc tests.
Browse files Browse the repository at this point in the history
git-svn-id: http://geokit.rubyforge.org/svn/trunk@31 9265c765-0211-4c68-b2df-6d1bd6e20c4d
  • Loading branch information
bill_eisenhauer committed May 23, 2007
1 parent a7e2d05 commit ed6cc61
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/geo_kit/mappable.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ def street_name
# gives you all the important fields as key-value pairs # gives you all the important fields as key-value pairs
def hash def hash
res={} res={}
[:success,:lat,:lng,:country_code,:city,:state,:zip,:street_address,:provider,:full_address,:ll,:is_us,:precision].each {|s|res[s]=self.send(s.to_s)} [:success,:lat,:lng,:country_code,:city,:state,:zip,:street_address,:provider,:full_address,:is_us?,:ll,:precision].each { |s| res[s] = self.send(s.to_s) }
res res
end end
alias to_hash hash


# Sets the city after capitalizing each word within the city name. # Sets the city after capitalizing each word within the city name.
def city=(city) def city=(city)
Expand All @@ -210,8 +211,8 @@ def street_address=(address)
# Returns a comma-delimited string consisting of the street address, city, state, # Returns a comma-delimited string consisting of the street address, city, state,
# zip, and country code. Only includes those attributes that are non-blank. # zip, and country code. Only includes those attributes that are non-blank.
def to_geocodeable_s def to_geocodeable_s
a=[street_address,city,state,zip,country_code].compact a=[street_address, city, state, zip, country_code].compact
a.delete_if {|e| !e|| e==''} a.delete_if { |e| !e || e == '' }
a.join(', ') a.join(', ')
end end


Expand Down
49 changes: 49 additions & 0 deletions test/geoloc_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'test/unit'
require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))

class GeoLocTest < Test::Unit::TestCase #:nodoc: all

def setup
@loc = GeoKit::GeoLoc.new
end

def test_is_us
assert !@loc.is_us?
@loc.country_code = 'US'
assert @loc.is_us?
end

def test_street_number
@loc.street_address = '123 Spear St.'
assert_equal '123', @loc.street_number
end

def test_street_name
@loc.street_address = '123 Spear St.'
assert_equal 'Spear St.', @loc.street_name
end

def test_city
@loc.city = "san francisco"
assert_equal 'San Francisco', @loc.city
end

def test_full_address
@loc.city = 'San Francisco'
@loc.state = 'CA'
@loc.zip = '94105'
@loc.country_code = 'US'
assert_equal 'San Francisco, CA, 94105, US', @loc.full_address
@loc.full_address = 'Irving, TX, 75063, US'
assert_equal 'Irving, TX, 75063, US', @loc.full_address
end

def test_hash
@loc.city = 'San Francisco'
@loc.state = 'CA'
@loc.zip = '94105'
@loc.country_code = 'US'
@another = GeoKit::GeoLoc.new @loc.to_hash
assert_equal @loc, @another
end
end

0 comments on commit ed6cc61

Please sign in to comment.