Sha256: f0884f562b654ce37a6300094574b421f993af18ebdeb4f797927a675d5daa74

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 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 break as the lat long format is incorrect' do
    lat = -27.477541606
    long = 153.012244888
    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 correctly format a hash to a latlong' do
    lat = -27.477541606
    long = 153.012244888
    lat_long = { 'lat' => lat, 'lon' => long }
    geohash = EnrichmentDb::Geo::Locator.format_geo(lat_long)
    assert_equal 'r7hg9vu5ewzr', 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

8 entries across 8 versions & 1 rubygems

Version Path
enrichment_db-0.1.15 test/geo/locator_test.rb
enrichment_db-0.1.14 test/geo/locator_test.rb
enrichment_db-0.1.13 test/geo/locator_test.rb
enrichment_db-0.1.12 test/geo/locator_test.rb
enrichment_db-0.1.11 test/geo/locator_test.rb
enrichment_db-0.1.10 test/geo/locator_test.rb
enrichment_db-0.1.9 test/geo/locator_test.rb
enrichment_db-0.1.8 test/geo/locator_test.rb