Sha256: 8dcb4ca6a7c159fffcc1198bdcc75302abefb8821dd81ea53bd78713b40f6985

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'
require 'earth/locality/zip_code'

describe ZipCode do
  describe 'when importing data', :data_miner => true do
    before do
      Earth.init :locality, :load_data_miner => true, :skip_parent_associations => :true
    end
    
    it 'imports data' do
      ZipCode.run_data_miner!
    end
  end
  
  describe 'verify imported data', :sanity => true do
    it { ZipCode.count.should == 43770 }
    it { ZipCode.where(:state_postal_abbreviation => nil).count.should == 0 }
    it { ZipCode.where('latitude IS NOT NULL AND longitude IS NOT NULL').count.should == 43191 }
    it { ZipCode.where('egrid_subregion_abbreviation IS NOT NULL').count.should == 41333 }
    it { ZipCode.where('climate_division_name IS NOT NULL').count.should == 41358 }
    it { ZipCode.where('population IS NOT NULL').count.should == 33120 }
  end
  
  describe '#country' do
    before do
      require 'earth/locality/country'
    end
    
    it 'should return the US' do
      ZipCode.first.country.should == Country.united_states
      ZipCode.last.country.should == Country.united_states
    end
  end
  
  describe '#latitude_longitude' do
    it 'should return the lat and lng as an array of strings' do
      ZipCode.find('00001').latitude_longitude.should == [nil, nil]
      ZipCode.find('00210').latitude_longitude.should == ['43.005895', '-71.013202']
    end
  end
  
  # from acts_as_mappable
  describe '.find_within' do
    it { ZipCode.find_within(15, :units => :kms, :origin => ZipCode.find('05753').latitude_longitude).count.should == 7 }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
earth-0.12.3 spec/earth/locality/zip_code_spec.rb
earth-0.12.2 spec/earth/locality/zip_code_spec.rb