Sha256: 5a08291e83e3606cd9c8034e10003802e708895a4a81edca49cc148481b070f6

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 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
  
  # 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
  
  describe '.known_subregion' do
    it { ZipCode.known_subregion.where(:egrid_subregion_abbreviation => nil).count.should == 0 }
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
earth-0.12.4 spec/earth/locality/zip_code_spec.rb