# encoding: utf-8 require 'test_helper' class TestCountry < MiniTest::Unit::TestCase def setup @br = Uncharted::Country.find('BR') end def test_country_lookup assert @br, "BR must exist" assert_equal 'BR', @br.alpha2 assert_equal 'BRA', @br.alpha3 assert_equal 'Brazil', @br.name(locale: :en) end def test_country_find @us = Country.find('US') assert_equal [@br, @us], Country.find([@br.alpha2, @us.alpha2]) assert_equal @us, Country.find(@us) end def test_to_s assert_equal 'BR', @br.to_s end def test_territories df = Territory.find('BR-DF') assert_equal @br, df.country assert_equal [df], @br.districts assert_equal 26, @br.states.count assert_equal 27, @br.subdivisions.count assert @br.territories.empty? pr = Territory.find('BR-PR') assert_equal 'ParanĂ¡', pr.name assert_equal 'PR', pr.abbr assert_equal 'PR', pr.to_s end def test_classes assert_equal Country, Uncharted::Country assert_equal Territory, Uncharted::Territory end def test_country_collection assert_equal 247, Country.countries.count end def test_translation assert_equal "Brazil", @br.name(locale: :en) assert_equal "Brasil", @br.name(locale: :'pt-BR') end def test_inspection assert_equal "BR: 'Brazil'", @br.inspect end def test_find_by_name assert_equal Country.find('US'), Country.find_by_name('States United') assert_equal Country.find('GB'), Country.find_by_name('Kingdom') assert_equal Country.find('FR'), Country.find_by_name('France') assert_equal Territory.find('BR-PR'), Territory.find_by_name('ParanĂ¡') assert_equal Territory.find('BR-RN'), Territory.find_by_name('Rio Grande do Norte') assert_equal Territory.find('BR-RS'), Territory.find_by_name('R Grande do Sul') end end