Skip to content

Commit

Permalink
Test for issue with Fallbacks and enforce_available_locales
Browse files Browse the repository at this point in the history
Created a test-case for an issue where the
Fallbacks module will generate an
I18n::InvalidLocale error.

Fallbacks relies on I18n.translation to find out
whether there's a translation for a fallback
locale (e.g. :'de' for :'de-DE'). But
I18n.translation does not distinguish from a
"user" call and one coming from the Fallbacks
module, and may raise I18n::InvalidLocale if
enforce_available_locales is set.
  • Loading branch information
romuloceccon committed Dec 7, 2013
1 parent f00149c commit d100659
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/backend/fallbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def setup
store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en')
store_translations(:de, :bar => 'Bar in :de', :baz => 'Baz in :de')
store_translations(:'de-DE', :baz => 'Baz in :de-DE')
store_translations(:'pt-BR', :baz => 'Baz in :pt-BR')
end

test "still returns an existing translation as usual" do
Expand Down Expand Up @@ -74,6 +75,15 @@ def setup
test "should ensure that default is not splitted on new line char" do
assert_equal "Default \n Bar", I18n.t(:missing_bar, :default => "Default \n Bar")
end

test "should not raise error when enforce_available_locales is true, :'pt' is missing and default is a Symbol" do
I18n.enforce_available_locales = true
begin
assert_equal 'Foo', I18n.t(:'model.attrs.foo', :locale => :'pt-BR', :default => [:'attrs.foo', "Foo"])
ensure
I18n.enforce_available_locales = false
end
end
end

class I18nBackendFallbacksLocalizeTest < Test::Unit::TestCase
Expand Down

0 comments on commit d100659

Please sign in to comment.