Sha256: 9be477d6c9d1a476e44a3ca4c3fdb3e6a46e1451142e5a7cb1ef9822b2383b37

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require "#{File.dirname(__FILE__)}/../test_helper"

describe EnrichmentDb::Geo::Locator do
  it 'should find id from a hash of hashes' do
  	id = 2
  	data = { 'c' => { 'id' => 1,  'b_id' => id }, 'b' => { 'id' => 3 } }
  	region_type = 'b'
    result = EnrichmentDb::Geo::Locator.find_id(data, region_type)
    assert_equal id, result
  end

  it 'should correctly format a hash to a latlong' do
    lat = 10
    long = 180
    lat_long = { 'lat' => lat, 'long' => long }
    begin 
      geohash = EnrichmentDb::Geo::Locator.format_geo(lat_long)
    rescue EnrichmentDb::InvalidGeoPointFormat => e
      # Should get here
    else
      flunk('This should have errored out.')
    end
  end

  it 'should break as the lat long format is incorrect' do
    lat = 10
    long = 180
    lat_long = { 'lat' => lat, 'lon' => long }
    geohash = EnrichmentDb::Geo::Locator.format_geo(lat_long)
    assert_equal 'xczbzurypzpg', geohash
  end

  it 'should find region from geohash' do
    geo = 'r1r0g2e'
    result = EnrichmentDb::Geo::Locator.geo_locate(geo)
    assert_equal ':sa4', result.smallest_region.inspect
    assert_equal 'Melbourne - Inner', result.name
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
enrichment_db-0.1.7 test/geo/locator_test.rb
enrichment_db-0.1.6 test/geo/locator_test.rb
enrichment_db-0.1.5 test/geo/locator_test.rb