1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# -*- encoding: utf-8 -*-
require 'maxminddb'
describe MaxMindDB::Result::Subdivisions do
subject(:subdivisions) { described_class.new(raw_subdivisions) }
context "with multiple subdivisions" do
let(:raw_subdivisions) { [{
"geoname_id"=>5037779,
"iso_code"=>"MN",
"names"=>{"en"=>"Minnesota"}
}, {
"geoname_id"=>123,
"iso_code"=>"HP",
"names"=>{"en"=>"Hennepin"}
}] }
it 'should be a kind of Array' do
expect(subdivisions).to be_kind_of(Array)
end
it 'should return as many items as there are subdivisions passed in' do
expect(subdivisions.length).to eq(raw_subdivisions.length)
end
it 'should contain only MaxMindDB::Result::NamedLocation' do
expect(subdivisions.all? { |r| r.kind_of?(MaxMindDB::Result::NamedLocation)}).to be_truthy
end
describe "most_specific" do
it 'should be a kind of MaxMindDB::Result::NamedLocation' do
expect(subdivisions.most_specific).to be_kind_of(MaxMindDB::Result::NamedLocation)
end
it 'should eq "Hennepin" subdivision' do
expect(subdivisions.most_specific.name).to eq("Hennepin")
end
end
end
context "without a result" do
let(:raw_subdivisions) { nil }
it 'should be a kind of Array' do
expect(subdivisions).to be_kind_of(Array)
end
it 'should be empty' do
expect(subdivisions.length).to eq(0)
end
describe "most_specific" do
it 'should be a kind of MaxMindDB::Result::NamedLocation' do
expect(subdivisions.most_specific).to be_kind_of(MaxMindDB::Result::NamedLocation)
end
it 'should be an empty MaxMindDB::Result::NamedLocation' do
expect(subdivisions.most_specific.code).to eq(nil)
expect(subdivisions.most_specific.geoname_id).to eq(nil)
expect(subdivisions.most_specific.iso_code).to eq(nil)
expect(subdivisions.most_specific.name).to eq(nil)
end
end
end
end
|