Permalink
Browse files

First tests

  • Loading branch information...
1 parent b821532 commit baf11cb8b343a2ad1928148c3959c16b2d738b96 Gilson Ferraz committed Aug 27, 2011
Showing with 82 additions and 1 deletion.
  1. +13 −0 lib/uncharted.rb
  2. +24 −0 lib/uncharted/country.rb
  3. +10 −0 lib/uncharted/country_data.rb
  4. +17 −0 test/country_test.rb
  5. +17 −0 test/uncharted_test.rb
  6. +1 −1 uncharted.gemspec
View
@@ -0,0 +1,13 @@
+
+
+require 'uncharted/country'
+
+Country = Uncharted::Country
+
+module Uncharted
+
+ def self.load(source)
+ source.each {|data| Country.new(data)}
+ end
+
+end
View
@@ -0,0 +1,24 @@
+
+module Uncharted
+ class Country
+
+ attr_reader :alpha2, :alpha3
+
+ def self.countries
+ @countries ||= {}
+ end
+
+ def initialize(params)
+ @alpha2 = params[:alpha2]
+ @alpha3 = params[:alpha3]
+ @names = params[:names] || {}
+ Country.countries[@alpha2] = self
+ end
+
+ def name(language)
+ @names[language]
+ end
+
+
+ end
+end
@@ -0,0 +1,10 @@
+
+require 'country'
+
+Uncharted::Country.new(alpha2: 'AR', alpha3: 'ARG',
+ names: {en: 'Argentina', pt: 'Argentina'},
+ territories: {
+ 'BA': {names: {en: 'Buenos Aires'}
+ }
+ )
+Uncharted::Country.new(alpha2: 'BR', alpha3: 'BRA', names: {en: 'Brazil', pt: 'Brasil')
View
@@ -0,0 +1,17 @@
+
+require 'test_helper'
+require 'uncharted'
+
+class TestUncharted < MiniTest::Unit::TestCase
+
+ def test_country_addition
+ Country.new(alpha2: 'BR', alpha3: 'BRA', names: {pt: 'Brasil'})
+ br = Country.countries['BR']
+ assert br, "Country BR not added"
+ assert_equal 'BR', br.alpha2
+ assert_equal 'BRA', br.alpha3
+ assert_equal 'Brasil', br.name(:pt)
+ end
+
+
+end
View
@@ -0,0 +1,17 @@
+# encoding: utf-8
+require 'test_helper'
+require 'uncharted'
+
+class TestUncharted < MiniTest::Unit::TestCase
+
+ COUNTRY_DATA = [
+ {alpha2: 'AR', alpha3: 'ARG', name: 'Argentina'},
+ {alpha2: 'BR', alpha3: 'BRA', name: 'Brasil', names: {fr: 'Brésil', pt: 'Brasil'}},
+ {alpha2: 'US', alpha3: 'USA', name: 'United States', names: {en: 'United States', pt: 'Estados Unidos'}}
+ ]
+
+ def test_load
+ Uncharted.load(COUNTRY_DATA)
+ assert_equal 3, Country.countries.count
+ end
+end
View
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
s.authors = ["Gilson Ferraz"]
s.email = ["gferraz@cenize.com"]
- s.summary = "ISO 3166 Countries & territories codes"
+ s.summary = "ISO 3166 Countries & territories codes (NOT READY FOR USE YET!)"
s.description = "Provide ISO 3166 codes and english name for countries and their political divisions"
s.homepage = "http://github.com/cenize/uncharted"

0 comments on commit baf11cb

Please sign in to comment.