spec/data_spec.rb in countries-4.2.3 vs spec/data_spec.rb in countries-5.0.0
- old
+ new
@@ -1,6 +1,7 @@
-# encoding: utf-8
+# frozen_string_literal: true
+
require 'spec_helper'
require 'benchmark'
describe ISO3166::Data do
it 'responds to call' do
@@ -8,17 +9,17 @@
expect(data['translated_names']).to be_a Array
end
it 'can load selective locales' do
# ISO3166::Data.update_cache
- ISO3166.configuration.locales = [:es, :de, :en]
+ ISO3166.configuration.locales = %i[es de en]
data = ISO3166::Data.new('US').call
expect(data['translated_names'].size).to eq 3
end
it 'can load selective locales and reload efficiently' do
- ISO3166.configuration.locales = [:es, :de, :en]
+ ISO3166.configuration.locales = %i[es de en]
data = ISO3166::Data.new('US').call
expect(data['translations']).to eq('de' => 'Vereinigte Staaten', 'es' => 'Estados Unidos', 'en' => 'United States')
expect(data['translated_names'].sort).to eq ['Vereinigte Staaten', 'Estados Unidos', 'United States'].sort
ISO3166.configuration.locales = [:en]
data = ISO3166::Data.new('US').call
@@ -33,20 +34,25 @@
end
end
it 'locales will load prior to return results' do
# require 'memory_profiler'
- ISO3166.configuration.locales = [:es, :de, :en]
+ ISO3166.configuration.locales = %i[es de en]
# report = MemoryProfiler.report do
ISO3166::Data.update_cache
# end
# report.pretty_print(to_file: 'tmp/memory/3_locales')
ISO3166::Data.update_cache
ISO3166.configure do |config|
- 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]
+ config.locales = %i[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]
end
# puts Benchmark.measure {ISO3166::Data.update_cache}
# report = MemoryProfiler.report do
ISO3166::Data.update_cache
@@ -59,48 +65,48 @@
expect(ISO3166.configuration.loaded_locales.size).to eq 92
end
it 'locales will load prior and be cached' do
ISO3166.reset
- ISO3166.configuration.locales = [:es, :de, :en]
- expect(ISO3166::Data.send(:locales_to_load)).to eql(%w(es de en))
+ ISO3166.configuration.locales = %i[es de en]
+ expect(ISO3166::Data.send(:locales_to_load)).to eql(%w[es de en])
ISO3166::Data.update_cache
- ISO3166.configuration.locales = [:es, :de, :en]
+ ISO3166.configuration.locales = %i[es de en]
expect(ISO3166::Data.send(:locales_to_load)).to eql([])
end
it 'locales will load prior and be cached' do
ISO3166.reset
- ISO3166.configuration.locales = [:es, :de, :en]
+ ISO3166.configuration.locales = %i[es de en]
expect(ISO3166::Data.send(:locales_to_remove)).to eql([])
expect(ISO3166::Country.new('DE').translation('de')).to eq 'Deutschland'
ISO3166::Data.update_cache
- ISO3166.configuration.locales = [:es, :en]
+ ISO3166.configuration.locales = %i[es en]
expect(ISO3166::Data.send(:locales_to_remove)).to eql(['de'])
expect(ISO3166::Country.new('DE').translation('de')).to eq nil
end
describe '#load_cache' do
it 'will return an empty hash for an unsupported locale' do
- file_array = %w(locales unsupported.json)
+ file_array = %w[locales unsupported.json]
expect(ISO3166::Data.send(:load_cache, file_array)).to eql({})
end
it 'will return json for a supported locale' do
- file_array = %w(locales en.json)
+ file_array = %w[locales en.json]
expect(ISO3166::Data.send(:load_cache, file_array)).not_to be_empty
end
end
describe 'hotloading existing data' do
before do
ISO3166::Data.register(
alpha2: 'TW',
iso_short_name: 'NEW Taiwan',
subdivisions: {
- CHA: {name: 'New Changhua'},
- CYI: {name: 'New Municipality'}
+ CHA: { name: 'New Changhua' },
+ CYI: { name: 'New Municipality' }
},
translations: {
'en' => 'NEW Taiwan',
'de' => 'NEW Taiwan'
}
@@ -114,22 +120,22 @@
ISO3166.configuration.locales = [:es, :de, :de]
expect(data['iso_short_name']).to eq 'NEW Taiwan'
expect(subject.iso_short_name).to eq 'NEW Taiwan'
expect(subject.translations).to eq('en' => 'NEW Taiwan',
'de' => 'NEW Taiwan')
- expect(subject.subdivisions).to eq('CHA' => ISO3166::Subdivision.new({name: 'New Changhua', code: 'CHA'}),
- 'CYI' => ISO3166::Subdivision.new({name: 'New Municipality', code: 'CYI'}))
+ expect(subject.subdivisions).to eq('CHA' => ISO3166::Subdivision.new({ name: 'New Changhua', code: 'CHA' }),
+ 'CYI' => ISO3166::Subdivision.new({ name: 'New Municipality', code: 'CYI' }))
end
end
describe 'hotloading data' do
before do
ISO3166::Data.register(
alpha2: 'LOL',
iso_short_name: 'Happy Country',
subdivisions: {
- LOL1: {name: 'Happy sub1'},
- LOL2: {name: 'Happy sub2'}
+ LOL1: { name: 'Happy sub1' },
+ LOL2: { name: 'Happy sub2' }
},
translations: {
'en' => 'Happy Country',
'de' => 'glückliches Land'
}