public
Description: ruby binding to maxmind geoip library
Homepage: http://geoip-city.rubyforge.org
Clone URL: git://github.com/ry/geoip-city.git
Ryan Dahl (author)
Tue Mar 04 14:58:58 -0800 2008
commit  94e8ce6f3da3a23f2a9e35102e7e797276b7e54c
tree    a82ecb8e6ca772b7117dfc247662648268225eca
parent  ea200d82a199528effb8c6d9575dd71b28d59d30
geoip-city / test.rb
100644 60 lines (47 sloc) 1.338 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
49
50
51
52
53
54
55
56
57
58
59
60
require 'test/unit'
require 'rubygems'
require 'geoip_city'
require 'ruby-debug'
Debugger.start
 
class GeoIPTest < Test::Unit::TestCase
  
  def setup
    ## Change me!
    @dbfile = '/opt/GeoIP-1.4.2/share/GeoIP/GeoLiteCity.dat'
  end
  
  
  def test_construction_default
    db = GeoIPCity::Database.new(@dbfile)
    
    assert_raises TypeError do
      db.look_up(nil)
    end
    
    h = db.look_up('24.24.24.24')
    #debugger
    assert_kind_of Hash, h
    assert_equal 'Ithaca', h[:city]
    assert_equal 'United States', h[:country_name]
  end
 
  def test_construction_index
    db = GeoIPCity::Database.new(@dbfile, :index)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_construction_filesystem
    db = GeoIPCity::Database.new(@dbfile, :filesystem)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_construction_memory
    db = GeoIPCity::Database.new(@dbfile, :memory)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_construction_filesystem_check
    db = GeoIPCity::Database.new(@dbfile, :filesystem, true)
    h = db.look_up('24.24.24.24')
    assert_equal 'Ithaca', h[:city]
  end
 
  def test_bad_db_file
    assert_raises Errno::ENOENT do
      GeoIPCity::Database.new('/blah')
    end
  end
  
end