From 9da9b2e1cc314c8c2633303e17eb0d215757d58d Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 8 Jan 2021 17:47:28 +0100 Subject: [PATCH] DEV: Add i18n fallback specs (#11669) Those fail on the buggy i18n release (1.8.6) and pass on 1.8.5, 1.8.7 (the revert release), and with the second stab at thread safety on the current master (https://github.com/ruby-i18n/i18n/commit/63a79cb929770629e20f0645676065025c599662) --- spec/integrity/i18n_spec.rb | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/spec/integrity/i18n_spec.rb b/spec/integrity/i18n_spec.rb index 49cabe87eb4..2c7494274e5 100644 --- a/spec/integrity/i18n_spec.rb +++ b/spec/integrity/i18n_spec.rb @@ -24,7 +24,6 @@ def is_yaml_compatible?(english, translated) end describe "i18n integrity checks" do - it 'has an i18n key for each Trust Levels' do TrustLevel.all.each do |ts| expect(ts.name).not_to match(/translation missing/) @@ -98,16 +97,46 @@ describe "i18n integrity checks" do end unless path["transliterate"] - it "is compatible with english" do expect(is_yaml_compatible?(english_yaml, yaml)).to eq(true) end - end - end + end + end +end +describe "fallbacks" do + before do + I18n.backend = I18n::Backend::DiscourseI18n.new + I18n.fallbacks = I18n::Backend::FallbackLocaleList.new + I18n.reload! + I18n.init_accelerator! + end + + it "finds the fallback translation" do + I18n.backend.store_translations(:en, test: "en test") + + I18n.with_locale("pl_PL") do + expect(I18n.t("test")).to eq("en test") end end + context "in a multi-threaded environment" do + it "finds the fallback translation" do + I18n.backend.store_translations(:en, test: "en test") + + thread = Thread.new do + I18n.with_locale("pl_PL") do + expect(I18n.t("test")).to eq("en test") + end + end + + begin + thread.join + ensure + thread.exit + end + end + end end