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