44 lines
1.5 KiB
Ruby
44 lines
1.5 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe MaxMindIsp do
|
|
|
|
include UsesTempFiles
|
|
|
|
ISP_CSV='small.csv'
|
|
|
|
in_directory_with_file(ISP_CSV)
|
|
|
|
before do
|
|
|
|
content_for_file('Copyright (c) 2011 MaxMind Inc. All Rights Reserved.
|
|
"beginIp","endIp","countryCode","ISP"
|
|
"1.0.0.0","1.0.0.255","AU","APNIC Debogon Project"
|
|
"1.0.1.0","1.0.1.255","CN","Chinanet Fujian Province Network"
|
|
"1.0.4.0","1.0.7.255","AU","Bigred,inc"'.encode(Encoding::ISO_8859_1))
|
|
|
|
MaxMindIsp.import_from_max_mind(ISP_CSV)
|
|
end
|
|
|
|
let(:first) { MaxMindIsp.find_by_ip_bottom(MaxMindIsp.ip_address_to_int('1.0.0.0')) }
|
|
let(:second) { MaxMindIsp.find_by_ip_bottom(MaxMindIsp.ip_address_to_int('1.0.1.0')) }
|
|
let(:third) { MaxMindIsp.find_by_ip_bottom(MaxMindIsp.ip_address_to_int('1.0.4.0')) }
|
|
|
|
it { MaxMindIsp.count.should == 3 }
|
|
|
|
it { first.country.should == 'AU' }
|
|
it { first.ip_bottom.should == MaxMindIsp.ip_address_to_int('1.0.0.0') }
|
|
it { first.ip_top.should == MaxMindIsp.ip_address_to_int('1.0.0.255') }
|
|
it { first.isp.should == 'APNIC Debogon Project' }
|
|
|
|
it { second.country.should == 'CN' }
|
|
it { second.ip_bottom.should == MaxMindIsp.ip_address_to_int('1.0.1.0') }
|
|
it { second.ip_top.should == MaxMindIsp.ip_address_to_int('1.0.1.255') }
|
|
it { second.isp.should == 'Chinanet Fujian Province Network' }
|
|
|
|
it { third.country.should == 'AU' }
|
|
it { third.ip_bottom.should == MaxMindIsp.ip_address_to_int('1.0.4.0') }
|
|
it { third.ip_top.should == MaxMindIsp.ip_address_to_int('1.0.7.255') }
|
|
it { third.isp.should == 'Bigred,inc' }
|
|
end
|
|
|