jam-cloud/ruby/spec/jam_ruby/models/max_mind_geo_spec.rb

39 lines
1.1 KiB
Ruby

require 'spec_helper'
describe MaxMindGeo do
include UsesTempFiles
GEO_CSV='small.csv'
in_directory_with_file(GEO_CSV)
before do
content_for_file('startIpNum,endIpNum,country,region,city,postalCode,latitude,longitude,dmaCode,areaCode
0.116.0.0,0.119.255.255,"AT","","","",47.3333,13.3333,123,123
1.0.0.0,1.0.0.255,"AU","","","",-27.0000,133.0000,,
1.0.1.0,1.0.1.255,"CN","07","Fuzhou","",26.0614,119.3061,,'.encode(Encoding::ISO_8859_1))
MaxMindGeo.import_from_max_mind(GEO_CSV)
end
it { MaxMindGeo.count.should == 3 }
let(:first) { MaxMindGeo.find_by_ip_start('0.116.0.0') }
let(:second) { MaxMindGeo.find_by_ip_start('1.0.0.0') }
let(:third) { MaxMindGeo.find_by_ip_start('1.0.1.0') }
it { first.country.should == 'AT' }
it { first.ip_start.should == '0.116.0.0' }
it { first.ip_end.should == '0.119.255.255' }
it { second.country.should == 'AU' }
it { second.ip_start.should == '1.0.0.0' }
it { second.ip_end.should == '1.0.0.255' }
it { third.country.should == 'CN' }
it { third.ip_start.should == '1.0.1.0' }
it { third.ip_end.should == '1.0.1.255' }
end