countries 1.2.5 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/CHANGELOG.md +6 -2
  4. data/Gemfile +1 -0
  5. data/README.markdown +33 -7
  6. data/Rakefile +15 -20
  7. data/countries.gemspec +1 -1
  8. data/lib/countries/cache/countries +0 -0
  9. data/lib/countries/cache/locales/af +0 -0
  10. data/lib/countries/cache/locales/am +0 -0
  11. data/lib/countries/cache/locales/ar +0 -0
  12. data/lib/countries/cache/locales/as +0 -0
  13. data/lib/countries/cache/locales/az +0 -0
  14. data/lib/countries/cache/locales/be +0 -0
  15. data/lib/countries/cache/locales/bg +0 -0
  16. data/lib/countries/cache/locales/bn +0 -0
  17. data/lib/countries/cache/locales/br +0 -0
  18. data/lib/countries/cache/locales/bs +0 -0
  19. data/lib/countries/cache/locales/ca +0 -0
  20. data/lib/countries/cache/locales/cs +0 -0
  21. data/lib/countries/cache/locales/cy +0 -0
  22. data/lib/countries/cache/locales/da +0 -0
  23. data/lib/countries/cache/locales/de +0 -0
  24. data/lib/countries/cache/locales/dz +0 -0
  25. data/lib/countries/cache/locales/el +0 -0
  26. data/lib/countries/cache/locales/en +0 -0
  27. data/lib/countries/cache/locales/eo +0 -0
  28. data/lib/countries/cache/locales/es +0 -0
  29. data/lib/countries/cache/locales/et +0 -0
  30. data/lib/countries/cache/locales/eu +0 -0
  31. data/lib/countries/cache/locales/fa +0 -0
  32. data/lib/countries/cache/locales/fi +0 -0
  33. data/lib/countries/cache/locales/fo +0 -0
  34. data/lib/countries/cache/locales/fr +0 -0
  35. data/lib/countries/cache/locales/ga +0 -0
  36. data/lib/countries/cache/locales/gl +0 -0
  37. data/lib/countries/cache/locales/gu +0 -0
  38. data/lib/countries/cache/locales/he +0 -0
  39. data/lib/countries/cache/locales/hi +0 -0
  40. data/lib/countries/cache/locales/hr +0 -0
  41. data/lib/countries/cache/locales/hu +0 -0
  42. data/lib/countries/cache/locales/hy +0 -0
  43. data/lib/countries/cache/locales/ia +0 -0
  44. data/lib/countries/cache/locales/id +0 -0
  45. data/lib/countries/cache/locales/is +0 -0
  46. data/lib/countries/cache/locales/it +0 -0
  47. data/lib/countries/cache/locales/ja +0 -0
  48. data/lib/countries/cache/locales/ka +0 -0
  49. data/lib/countries/cache/locales/kk +0 -0
  50. data/lib/countries/cache/locales/km +0 -0
  51. data/lib/countries/cache/locales/kn +0 -0
  52. data/lib/countries/cache/locales/ko +0 -0
  53. data/lib/countries/cache/locales/ku +0 -0
  54. data/lib/countries/cache/locales/lt +0 -0
  55. data/lib/countries/cache/locales/lv +0 -0
  56. data/lib/countries/cache/locales/mi +0 -0
  57. data/lib/countries/cache/locales/mk +0 -0
  58. data/lib/countries/cache/locales/ml +0 -0
  59. data/lib/countries/cache/locales/mn +0 -0
  60. data/lib/countries/cache/locales/mr +0 -0
  61. data/lib/countries/cache/locales/ms +0 -0
  62. data/lib/countries/cache/locales/mt +0 -0
  63. data/lib/countries/cache/locales/nb +0 -0
  64. data/lib/countries/cache/locales/ne +0 -0
  65. data/lib/countries/cache/locales/nl +0 -0
  66. data/lib/countries/cache/locales/nn +0 -0
  67. data/lib/countries/cache/locales/oc +0 -0
  68. data/lib/countries/cache/locales/or +0 -0
  69. data/lib/countries/cache/locales/pa +0 -0
  70. data/lib/countries/cache/locales/pl +0 -0
  71. data/lib/countries/cache/locales/ps +0 -0
  72. data/lib/countries/cache/locales/pt +0 -0
  73. data/lib/countries/cache/locales/ro +0 -0
  74. data/lib/countries/cache/locales/ru +0 -0
  75. data/lib/countries/cache/locales/rw +0 -0
  76. data/lib/countries/cache/locales/si +0 -0
  77. data/lib/countries/cache/locales/sk +0 -0
  78. data/lib/countries/cache/locales/sl +0 -0
  79. data/lib/countries/cache/locales/so +0 -0
  80. data/lib/countries/cache/locales/sq +0 -0
  81. data/lib/countries/cache/locales/sr +0 -0
  82. data/lib/countries/cache/locales/sv +0 -0
  83. data/lib/countries/cache/locales/sw +0 -0
  84. data/lib/countries/cache/locales/ta +0 -0
  85. data/lib/countries/cache/locales/te +0 -0
  86. data/lib/countries/cache/locales/th +0 -0
  87. data/lib/countries/cache/locales/ti +0 -0
  88. data/lib/countries/cache/locales/tk +0 -0
  89. data/lib/countries/cache/locales/tl +0 -0
  90. data/lib/countries/cache/locales/tr +0 -0
  91. data/lib/countries/cache/locales/tt +0 -0
  92. data/lib/countries/cache/locales/ug +0 -0
  93. data/lib/countries/cache/locales/uk +0 -0
  94. data/lib/countries/cache/locales/ve +0 -0
  95. data/lib/countries/cache/locales/vi +0 -0
  96. data/lib/countries/cache/locales/wa +0 -0
  97. data/lib/countries/cache/locales/wo +0 -0
  98. data/lib/countries/cache/locales/xh +0 -0
  99. data/lib/countries/cache/locales/zh +0 -0
  100. data/lib/countries/cache/locales/zu +0 -0
  101. data/lib/countries/configuration.rb +37 -0
  102. data/lib/countries/country.rb +115 -159
  103. data/lib/countries/country/attr_readers.rb +49 -0
  104. data/lib/countries/data.rb +76 -13
  105. data/lib/countries/iso3166.rb +4 -2
  106. data/lib/countries/setup.rb +7 -7
  107. data/lib/countries/timezones.rb +11 -0
  108. data/lib/countries/version.rb +1 -1
  109. data/spec/configuration_spec.rb +43 -0
  110. data/spec/country_spec.rb +22 -36
  111. data/spec/data_spec.rb +73 -0
  112. data/spec/global_spec.rb +29 -0
  113. data/spec/mongoid_spec.rb +1 -1
  114. data/spec/spec_helper.rb +24 -0
  115. data/spec/timezone_spec.rb +32 -0
  116. metadata +110 -9
  117. data/spec/setup_spec.rb +0 -14
@@ -0,0 +1,49 @@
1
+ module ISO3166
2
+ module Countries
3
+ module AttrReaders
4
+ AttrReaders = [
5
+ :number,
6
+ :alpha2,
7
+ :alpha3,
8
+ :name,
9
+ :names,
10
+ :latitude,
11
+ :longitude,
12
+ :continent,
13
+ :region,
14
+ :subregion,
15
+ :world_region,
16
+ :country_code,
17
+ :national_destination_code_lengths,
18
+ :national_number_lengths,
19
+ :international_prefix,
20
+ :national_prefix,
21
+ :address_format,
22
+ :translations,
23
+ :translated_names,
24
+ :ioc,
25
+ :gec,
26
+ :un_locode,
27
+ :languages,
28
+ :nationality,
29
+ :dissolved_on,
30
+ :eu_member,
31
+ :alt_currency,
32
+ :vat_rates,
33
+ :postal_code,
34
+ :min_longitude,
35
+ :min_latitude,
36
+ :max_longitude,
37
+ :max_latitude,
38
+ :latitude_dec,
39
+ :longitude_dec
40
+ ]
41
+
42
+ AttrReaders.each do |meth|
43
+ define_method meth do
44
+ @data[meth.to_s]
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -4,30 +4,93 @@ module ISO3166
4
4
  class Data
5
5
  @@cache = nil
6
6
  def initialize(alpha2)
7
+ self.class.update_cache
7
8
  @alpha2 = alpha2.to_s.upcase
8
- Data.load_cache unless @@cache
9
9
  end
10
10
 
11
11
  def call
12
12
  @@cache[@alpha2]
13
13
  end
14
14
 
15
- def self.codes
16
- @@codes ||= Data.load_yaml(['countries', 'data', 'countries.yaml']).freeze
17
- end
15
+ class << self
16
+ def cache
17
+ update_cache
18
+ end
18
19
 
19
- private
20
+ def reset
21
+ @@cache = nil
22
+ @@codes = nil
23
+ end
20
24
 
21
- def self.datafile_path(file_array)
22
- File.join([File.dirname(__FILE__), '..'] + file_array)
23
- end
25
+ def codes
26
+ @@codes ||= load_yaml(['data', 'countries.yaml']).freeze
27
+ end
24
28
 
25
- def self.load_yaml(file_array)
26
- YAML.load_file(datafile_path(file_array))
27
- end
29
+ def update_cache
30
+ return @@cache unless cache_flush_required?
31
+ @@cache ||= marshal %w(cache countries )
32
+
33
+ locales_to_remove.each do |locale|
34
+ unload_translations(locale)
35
+ end
36
+
37
+ locales_to_load.each do |locale|
38
+ load_translations(locale)
39
+ end
40
+
41
+ @@cache.freeze
42
+ end
43
+
44
+ private
45
+ def cache_flush_required?
46
+ locales_to_load.size && locales_to_remove.size
47
+ end
48
+
49
+ def locales_to_load
50
+ requested_locales - loaded_locales
51
+ end
52
+
53
+ def locales_to_remove
54
+ loaded_locales - requested_locales
55
+ end
56
+
57
+ def requested_locales
58
+ ISO3166.configuration.locales.map { |l| l.to_s.downcase }
59
+ end
60
+
61
+ def loaded_locales
62
+ ISO3166.configuration.loaded_locales.map { |l| l.to_s.downcase }
63
+ end
64
+
65
+ def load_translations(locale)
66
+ locale_names = marshal(['cache', 'locales', locale])
67
+ codes.each do |alpha2|
68
+ @@cache[alpha2]['translations'] ||= {}
69
+ @@cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
70
+ @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
71
+ end
72
+ ISO3166.configuration.loaded_locales << locale
73
+ end
74
+
75
+ def unload_translations(locale)
76
+ codes.each do |alpha2|
77
+ @@cache[alpha2]['translations'].delete(locale)
78
+ @@cache[alpha2]['translated_names'] = @@cache[alpha2]['translations'].values.freeze
79
+ end
80
+ ISO3166.configuration.loaded_locales.delete(locale)
81
+ end
82
+
83
+ def marshal(file_array)
84
+ Marshal.load(File.binread(datafile_path file_array))
85
+ end
86
+
87
+ def datafile_path(file_array)
88
+ File.join([File.dirname(__FILE__)] + file_array)
89
+ end
28
90
 
29
- def self.load_cache
30
- @@cache ||= Marshal.load(File.binread(datafile_path %w(countries cache countries )))
91
+ def load_yaml(file_array)
92
+ YAML.load_file(datafile_path(file_array))
93
+ end
31
94
  end
32
95
  end
33
96
  end
@@ -1,7 +1,9 @@
1
1
  require 'yaml'
2
- require 'iso4217'
3
2
  require 'i18n_data'
3
+ require 'money'
4
4
 
5
- require 'countries/setup'
5
+ require 'countries/configuration'
6
6
  require 'countries/data'
7
+ require 'countries/country/attr_readers'
7
8
  require 'countries/country'
9
+ require 'countries/timezones'
@@ -1,18 +1,18 @@
1
1
  module ISO3166
2
2
  ##
3
+ # <b>DEPRECATED:</b> Please use <tt>Data</tt> instead.
4
+ # TODO: Remove at version 2.1
3
5
  # Handles building the in memory store of countries data
4
6
  class Setup
7
+ # <b>DEPRECATED:</b> Please use <tt>Data.codes</tt> instead.
5
8
  def codes
6
- @codes ||= Data.codes
9
+ warn "[DEPRECATION] `Setup.codes` is deprecated. Please use `Data.codes` instead."
10
+ Data.codes
7
11
  end
8
12
 
9
13
  def data
10
- return @data if instance_variable_defined?('@data')
11
- @data = {}
12
- codes.each do |alpha2|
13
- @data[alpha2] = Data.new(alpha2).call
14
- end
15
- @data.freeze
14
+ warn "[DEPRECATION] `Setup.new.data` is deprecated without replacement
15
+ data is now loaded per locale Data.new(:en).call"
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,11 @@
1
+ # Extend Country class with support for timezones
2
+ module ISO3166
3
+ # Extend Country class with support for timezones
4
+ module TimezoneExtensions
5
+ def timezones
6
+ @tz_country ||= TZInfo::Country.get(alpha2)
7
+ end
8
+ end
9
+ end
10
+
11
+ ISO3166::Country.send(:include, ISO3166::TimezoneExtensions)
@@ -1,3 +1,3 @@
1
1
  module Countries
2
- VERSION = '1.2.5'
2
+ VERSION = '2.0.0.pre'
3
3
  end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'ISO3166.configuration' do
5
+ it 'has a configuration' do
6
+ expect(ISO3166.configuration).to be_a ISO3166::Configuration
7
+ end
8
+
9
+ it 'locales can be changed' do
10
+ ISO3166.configuration.locales = [:es]
11
+ expect(ISO3166.configuration.locales).to eq [:es]
12
+ end
13
+
14
+ it 'locales are assumed from I18n.available_locales' do
15
+ I18n.available_locales = [:de, :en]
16
+ ISO3166.reset
17
+ expect(ISO3166::Country.new('DE').translation(:de)).to eq 'Deutschland'
18
+ expect(ISO3166::Country.new('DE').translation(:es)).to eq nil
19
+ end
20
+
21
+ it 'locales can be changed' do
22
+ ISO3166.configuration.locales = [:de]
23
+ expect(ISO3166::Country.new('DE').translation(:de)).to eq 'Deutschland'
24
+ expect(ISO3166::Country.new('DE').translation(:es)).to eq nil
25
+ end
26
+
27
+ it 'locales can be changed' do
28
+ ISO3166.configuration.locales = [:es, :de, :en]
29
+ expect(ISO3166::Country.new('DE').translation(:es)).to eq 'Alemania'
30
+ expect(ISO3166::Country.new('DE').translation(:en)).to eq 'Germany'
31
+ expect(ISO3166::Country.new('DE').translation(:de)).to eq 'Deutschland'
32
+ end
33
+
34
+ it 'locales can be changed with a block' do
35
+ ISO3166.configure do |config|
36
+ config.locales = [:af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de, :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he, :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku, :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or, :pa, :pl, :ps, :pt, :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh, :zh, :zu]
37
+ end
38
+
39
+ expect(ISO3166::Country.new('DE').translations.size).to eq 92
40
+
41
+ expect(ISO3166.configuration.loaded_locales.size).to eq 92
42
+ end
43
+ end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'spec_helper'
4
4
 
5
5
  describe ISO3166::Country do
6
6
  let(:country) { ISO3166::Country.search('US') }
@@ -244,10 +244,21 @@ describe ISO3166::Country do
244
244
  expect(countries.first[0]).to eq('Afghanistan')
245
245
  expect(countries.size).to eq(250)
246
246
  end
247
+
248
+ it 'should return an alphabetized list of all country names translated to current locale with ISOCODE alpha2' do
249
+ ISO3166.configuration.locales = [:es, :de, :en]
250
+
251
+ countries = ISO3166::Country.all_names_with_codes(:es)
252
+ expect(countries).to be_an(Array)
253
+ expect(countries.first[0]).to be_a(String)
254
+ expect(countries.first[0]).to eq('Afganistán')
255
+ expect(countries.size).to eq(250)
256
+ end
247
257
  end
248
258
 
249
259
  describe 'translation' do
250
260
  it 'should return the localized name for a country to the selected locale' do
261
+ ISO3166.configuration.locales = [:es, :de, :en]
251
262
  countries = ISO3166::Country.new(:de).translation('de')
252
263
  expect(countries).to be_an(String)
253
264
  expect(countries).to eq('Deutschland')
@@ -311,41 +322,11 @@ describe ISO3166::Country do
311
322
 
312
323
  describe 'currency' do
313
324
  it 'should return an instance of Currency' do
314
- expect(country.currency).to be_a(ISO4217::Currency)
325
+ expect(country.currency).to be_a(Money::Currency)
315
326
  end
316
327
 
317
328
  it 'should allow access to symbol' do
318
- expect(country.currency[:symbol]).to eq('$')
319
- end
320
- end
321
-
322
- describe 'Country class' do
323
- context "when loaded via 'iso3166' existance" do
324
- subject { defined?(Country) }
325
-
326
- it { is_expected.to be_falsey }
327
- end
328
-
329
- context "when loaded via 'global'" do
330
- before { require 'countries/global' }
331
-
332
- describe 'existance' do
333
- subject { defined?(Country) }
334
-
335
- it { is_expected.to be_truthy }
336
- end
337
-
338
- describe 'superclass' do
339
- subject { Country.superclass }
340
-
341
- it { is_expected.to eq(ISO3166::Country) }
342
- end
343
-
344
- describe 'to_s' do
345
- it 'should return the country name' do
346
- expect(Country.new('GB').to_s).to eq('United Kingdom')
347
- end
348
- end
329
+ expect(country.currency.symbol).to eq('$')
349
330
  end
350
331
  end
351
332
 
@@ -467,6 +448,11 @@ describe ISO3166::Country do
467
448
  end
468
449
 
469
450
  context 'when search translation found' do
451
+ before do
452
+ ISO3166.configure do |config|
453
+ config.locales = [:af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de, :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he, :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku, :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or, :pa, :pl, :ps, :pt, :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh, :zh, :zu]
454
+ end
455
+ end
470
456
  let(:uk) { ISO3166::Country.find_country_by_translated_names('Velika Britanija') }
471
457
 
472
458
  it 'should be a country instance' do
@@ -556,7 +542,7 @@ describe ISO3166::Country do
556
542
 
557
543
  describe 'names in Data' do
558
544
  it 'should be unique (to allow .find_by_name work properly)' do
559
- names = ISO3166::Country::Setup.data.map do |_k, v|
545
+ names = ISO3166::Data.cache.map do |_k, v|
560
546
  [v['name'], v['names']].flatten.uniq
561
547
  end.flatten
562
548
 
@@ -568,7 +554,7 @@ describe ISO3166::Country do
568
554
  let(:norway) { ISO3166::Country.search('NO') }
569
555
 
570
556
  it 'should have a currency' do
571
- expect(norway.currency).to be_a(ISO4217::Currency)
557
+ expect(norway.currency).to be_a(Money::Currency)
572
558
  end
573
559
  end
574
560
 
@@ -576,7 +562,7 @@ describe ISO3166::Country do
576
562
  let(:guernsey) { ISO3166::Country.search('GG') }
577
563
 
578
564
  it 'should have a currency' do
579
- expect(guernsey.currency.code).to eq('GBP')
565
+ expect(guernsey.currency.iso_code).to eq('GBP')
580
566
  end
581
567
  end
582
568
 
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'benchmark'
4
+
5
+ describe ISO3166::Data do
6
+ it 'responds to call' do
7
+ data = ISO3166::Data.new('US').call
8
+ expect(data['translated_names']).to be_a Array
9
+ end
10
+
11
+ it 'can load selective locales' do
12
+ # ISO3166::Data.update_cache
13
+ ISO3166.configuration.locales = [:es, :de, :en]
14
+ data = ISO3166::Data.new('US').call
15
+ expect(data['translated_names'].size).to eq (3)
16
+ end
17
+
18
+ it 'can load selective locales and reload efficiently' do
19
+ ISO3166.configuration.locales = [:es, :de, :en]
20
+ data = ISO3166::Data.new('US').call
21
+ expect(data['translations']).to eq({"de"=>"Vereinigte Staaten", "es"=>"Estados Unidos", "en"=>"United States"})
22
+ expect(data['translated_names'].sort).to eq ["Vereinigte Staaten", "Estados Unidos", "United States"].sort
23
+ ISO3166.configuration.locales = [:en]
24
+ data = ISO3166::Data.new('US').call
25
+ expect(data['translated_names'].size).to eq (1)
26
+ end
27
+
28
+ it 'locales will load prior to return results' do
29
+ # require 'memory_profiler'
30
+ ISO3166.configuration.locales = [:es, :de, :en]
31
+ # report = MemoryProfiler.report do
32
+ ISO3166::Data.update_cache
33
+ # end
34
+
35
+ # report.pretty_print(to_file: 'tmp/memory/3_locales')
36
+ ISO3166::Data.update_cache
37
+
38
+ ISO3166.configure do |config|
39
+ config.locales = [:af, :am, :ar, :as, :az, :be, :bg, :bn, :br, :bs, :ca, :cs, :cy, :da, :de, :dz, :el, :en, :eo, :es, :et, :eu, :fa, :fi, :fo, :fr, :ga, :gl, :gu, :he, :hi, :hr, :hu, :hy, :ia, :id, :is, :it, :ja, :ka, :kk, :km, :kn, :ko, :ku, :lt, :lv, :mi, :mk, :ml, :mn, :mr, :ms, :mt, :nb, :ne, :nl, :nn, :oc, :or, :pa, :pl, :ps, :pt, :ro, :ru, :rw, :si, :sk, :sl, :so, :sq, :sr, :sv, :sw, :ta, :te, :th, :ti, :tk, :tl, :tr, :tt, :ug, :uk, :ve, :vi, :wa, :wo, :xh, :zh, :zu]
40
+ end
41
+ # puts Benchmark.measure {ISO3166::Data.update_cache}
42
+
43
+ # report = MemoryProfiler.report do
44
+ ISO3166::Data.update_cache
45
+ # end
46
+
47
+ # report.pretty_print(to_file: 'tmp/memory/all_locales')
48
+
49
+ expect(ISO3166::Country.new('DE').translations.size).to eq 92
50
+
51
+ expect(ISO3166.configuration.loaded_locales.size).to eq 92
52
+ end
53
+
54
+ it 'locales will load prior and be cached' do
55
+ ISO3166.reset
56
+ ISO3166.configuration.locales = [:es, :de, :en]
57
+ expect(ISO3166::Data.send(:locales_to_load) ).to eql(['es', 'de', 'en'])
58
+ ISO3166::Data.update_cache
59
+ ISO3166.configuration.locales = [:es, :de, :en]
60
+ expect(ISO3166::Data.send(:locales_to_load) ).to eql([])
61
+ end
62
+
63
+ it 'locales will load prior and be cached' do
64
+ ISO3166.reset
65
+ ISO3166.configuration.locales = [:es, :de, :en]
66
+ expect(ISO3166::Data.send(:locales_to_remove) ).to eql([])
67
+ expect(ISO3166::Country.new('DE').translation('de')).to eq 'Deutschland'
68
+ ISO3166::Data.update_cache
69
+ ISO3166.configuration.locales = [:es, :en]
70
+ expect(ISO3166::Data.send(:locales_to_remove) ).to eql(['de'])
71
+ expect(ISO3166::Country.new('DE').translation('de')).to eq nil
72
+ end
73
+ end
@@ -0,0 +1,29 @@
1
+ describe 'global Country class' do
2
+ context "when loaded via 'iso3166' existance" do
3
+ subject { defined?(Country) }
4
+
5
+ it { is_expected.to be_falsey }
6
+ end
7
+
8
+ context "when loaded via 'global'" do
9
+ before { require 'countries/global' }
10
+
11
+ describe 'existance' do
12
+ subject { defined?(Country) }
13
+
14
+ it { is_expected.to be_truthy }
15
+ end
16
+
17
+ describe 'superclass' do
18
+ subject { Country.superclass }
19
+
20
+ it { is_expected.to eq(ISO3166::Country) }
21
+ end
22
+
23
+ describe 'to_s' do
24
+ it 'should return the country name' do
25
+ expect(Country.new('GB').to_s).to eq('United Kingdom')
26
+ end
27
+ end
28
+ end
29
+ end