Parse available language string more relaxed

Splitting the string with any whitespace makes it more likely the code
knows what the human meant. It also makes `strip` obsolete, since there
can't be any whitespace within the splitted strings.
This commit is contained in:
Maikel Linke
2018-03-09 19:41:49 +11:00
parent 8017921e89
commit db61a2bb17
2 changed files with 6 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ module OpenFoodNetwork
# See: config/application.yml
class I18nConfig
def self.selectable_locales
ENV["AVAILABLE_LOCALES"].andand.split(/[\s,]/).andand.map(&:strip) || []
ENV["AVAILABLE_LOCALES"].andand.split(/[\s,]+/) || []
end
def self.available_locales

View File

@@ -77,17 +77,15 @@ module OpenFoodNetwork
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")
allow(ENV).to receive(:[]).with("AVAILABLE_LOCALES").and_return("es, fr ,, ,de")
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"]
it "provides the default selectable locales" do
expect(I18nConfig.selectable_locales).to eq ["es", "fr", "de"]
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"]
it "provides the default available locales" do
expect(I18nConfig.available_locales).to eq ["es", "fr", "de", "en"]
end
end
end