Sha256: 185380455aedbfb12ba084506b894f2d2e2c9571d6246ea72aafe47bb536331f

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

require 'test_helper'

class CountryTest < Minitest::Test
  def test_country_from_hash
    country = Country.new(:name => 'Canada', :alpha2 => 'CA', :alpha3 => 'CAN', :numeric => '124')
    assert_equal 'CA', country.code(:alpha2).value
    assert_equal 'CAN', country.code(:alpha3).value
    assert_equal '124', country.code(:numeric).value
    assert_equal 'Canada', country.to_s
  end

  def test_country_for_alpha2_code
    country = Country.find('CA')
    assert_equal 'CA', country.code(:alpha2).value
    assert_equal 'CAN', country.code(:alpha3).value
    assert_equal '124', country.code(:numeric).value
    assert_equal 'Canada', country.to_s
  end

  def test_country_for_alpha3_code
    country = Country.find('CAN')
    assert_equal 'Canada', country.to_s
  end

  def test_country_for_numeric_code
    country = Country.find('124')
    assert_equal 'Canada', country.to_s
  end

  def test_find_country_by_name
    country = Country.find('Canada')
    assert_equal 'Canada', country.to_s
  end

  def test_find_unknown_country_name
    assert_raises(InvalidCountryCodeError) do
      Country.find('Asskickistan')
    end
  end

  def test_find_australia
    country = Country.find('AU')
    assert_equal 'AU', country.code(:alpha2).value

    country = Country.find('Australia')
    assert_equal 'AU', country.code(:alpha2).value
  end

  def test_find_united_kingdom
    country = Country.find('GB')
    assert_equal 'GB', country.code(:alpha2).value

    country = Country.find('United Kingdom')
    assert_equal 'GB', country.code(:alpha2).value
  end

  def test_raise_on_nil_name
    assert_raises(InvalidCountryCodeError) do
      Country.find(nil)
    end
  end

  def test_country_names_are_alphabetized
    country_names = Country::COUNTRIES.map { | each | each[:name] }
    assert_equal(country_names.sort, country_names)
  end

end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
active_utils-3.1.0 test/unit/country_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/active_utils-2.2.3/test/unit/country_test.rb
tanga_active_utils-2.2.3.1 test/unit/country_test.rb
tanga_active_utils-2.2.3 test/unit/country_test.rb
active_utils-3.0.0 test/unit/country_test.rb
active_utils-3.0.0.pre3 test/unit/country_test.rb
active_utils-3.0.0.pre2 test/unit/country_test.rb
active_utils-3.0.0.pre1 test/unit/country_test.rb
active_utils-2.2.3 test/unit/country_test.rb
active_utils-2.2.2 test/unit/country_test.rb
active_utils-2.2.1 test/unit/country_test.rb
active_utils-2.2.0 test/unit/country_test.rb