mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-20 04:59:16 +00:00
Introduce I18nConfig as single point of truth
It will be used in application.rb and views. See https://github.com/openfoodfoundation/openfoodnetwork/issues/2113
This commit is contained in:
94
spec/lib/open_food_network/i18n_config_spec.rb
Normal file
94
spec/lib/open_food_network/i18n_config_spec.rb
Normal file
@@ -0,0 +1,94 @@
|
||||
require 'spec_helper'
|
||||
require 'open_food_network/i18n_config'
|
||||
|
||||
module OpenFoodNetwork
|
||||
describe I18nConfig do
|
||||
context "in default test configuration" do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with("LOCALE").and_return("en")
|
||||
allow(ENV).to receive(:[]).with("AVAILABLE_LOCALES").and_return("en,es")
|
||||
end
|
||||
|
||||
it "provides the source locale" do
|
||||
expect(I18nConfig.source_locale).to eq "en"
|
||||
end
|
||||
|
||||
it "provides the default locale" do
|
||||
expect(I18nConfig.default_locale).to eq "en"
|
||||
end
|
||||
|
||||
it "provides the default selectable locales" do
|
||||
expect(I18nConfig.selectable_locales).to eq ["en", "es"]
|
||||
end
|
||||
|
||||
it "provides the default available locales" do
|
||||
expect(I18nConfig.available_locales).to eq ["en", "es"]
|
||||
end
|
||||
end
|
||||
|
||||
context "without configuration" do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with("LOCALE").and_return(nil)
|
||||
allow(ENV).to receive(:[]).with("I18N_LOCALE").and_return(nil)
|
||||
allow(ENV).to receive(:[]).with("AVAILABLE_LOCALES").and_return(nil)
|
||||
end
|
||||
|
||||
it "provides the source locale" do
|
||||
expect(I18nConfig.source_locale).to eq "en"
|
||||
end
|
||||
|
||||
it "provides the default locale" do
|
||||
expect(I18nConfig.default_locale).to eq "en"
|
||||
end
|
||||
|
||||
it "provides the default selectable locales" do
|
||||
expect(I18nConfig.selectable_locales).to eq []
|
||||
end
|
||||
|
||||
it "provides the default available locales" do
|
||||
expect(I18nConfig.available_locales).to eq ["en"]
|
||||
end
|
||||
end
|
||||
|
||||
context "with UK configuration" do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with("LOCALE").and_return("en_GB")
|
||||
allow(ENV).to receive(:[]).with("I18N_LOCALE").and_return(nil)
|
||||
allow(ENV).to receive(:[]).with("AVAILABLE_LOCALES").and_return("en_GB")
|
||||
end
|
||||
|
||||
it "provides the source locale" do
|
||||
expect(I18nConfig.source_locale).to eq "en"
|
||||
end
|
||||
|
||||
it "provides the default locale" do
|
||||
expect(I18nConfig.default_locale).to eq "en_GB"
|
||||
end
|
||||
|
||||
it "provides the default selectable locales" do
|
||||
expect(I18nConfig.selectable_locales).to eq ["en_GB"]
|
||||
end
|
||||
|
||||
it "provides the default available locales" do
|
||||
expect(I18nConfig.available_locales).to eq ["en_GB", "en"]
|
||||
end
|
||||
end
|
||||
|
||||
context "with human syntax" do
|
||||
before do
|
||||
allow(ENV).to receive(:[]).with("LOCALE").and_return("es")
|
||||
allow(ENV).to receive(:[]).with("AVAILABLE_LOCALES").and_return("es, fr")
|
||||
end
|
||||
|
||||
xit "provides the default selectable locales" do
|
||||
# current: expect(I18nConfig.selectable_locales).to eq ["es", "", "fr"]
|
||||
expect(I18nConfig.selectable_locales).to eq ["es", "fr"]
|
||||
end
|
||||
|
||||
xit "provides the default available locales" do
|
||||
# current: expect(I18nConfig.available_locales).to eq ["es", "", "fr", "en"]
|
||||
expect(I18nConfig.available_locales).to eq ["es", "fr", "en"]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user