Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix bug: a default array of non-existant keys returns the default array

  • Loading branch information...
commit 6c04ca86c87f97dc78f07c2a4023644e5ba8b839 1 parent b406aa3
@svenfuchs authored
Showing with 11 additions and 5 deletions.
  1. +1 −1  lib/i18n/backend/simple.rb
  2. +10 −4 test/simple_backend_test.rb
View
2  lib/i18n/backend/simple.rb
@@ -89,7 +89,7 @@ def default(locale, default, options = {})
when Symbol then translate locale, default, options
when Array then default.each do |obj|
result = default(locale, obj, options.dup) and return result
- end
+ end and nil
end
rescue MissingTranslationData
nil
View
14 test/simple_backend_test.rb
@@ -123,6 +123,10 @@ def test_translate_calls_lookup_with_locale_given
@backend.translate 'de-DE', :bar, :scope => [:foo]
end
+ def test_given_no_keys_it_returns_the_default
+ assert_equal 'default', @backend.translate('en-US', nil, :default => 'default')
+ end
+
def test_translate_given_a_symbol_as_a_default_translates_the_symbol
assert_equal 'bar', @backend.translate('en-US', nil, :scope => [:foo], :default => :bar)
end
@@ -131,6 +135,12 @@ def test_translate_given_an_array_as_default_uses_the_first_match
assert_equal 'bar', @backend.translate('en-US', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :bar])
end
+ def test_translate_given_an_array_of_inexistent_keys_it_raises_missing_translation_data
+ assert_raises I18n::MissingTranslationData do
+ @backend.translate('en-US', :does_not_exist, :scope => [:foo], :default => [:does_not_exist_2, :does_not_exist_3])
+ end
+ end
+
def test_translate_an_array_of_keys_translates_all_of_them
assert_equal %w(bar baz), @backend.translate('en-US', [:bar, :baz], :scope => [:foo])
end
@@ -150,10 +160,6 @@ def test_translate_calls_interpolate_including_count_as_a_value
@backend.translate 'en-US', :bar, :scope => [:foo], :count => 1
end
- def test_given_no_keys_it_returns_the_default
- assert_equal 'default', @backend.translate('en-US', nil, :default => 'default')
- end
-
def test_translate_given_nil_as_a_locale_raises_an_argument_error
assert_raises(I18n::InvalidLocale){ @backend.translate nil, :bar }
end

2 comments on commit 6c04ca8

@masterkain

hi swen, I wonder: when this is going into the core? This fixes a nasty bug on AR errors when not en-US

@svenfuchs
Owner

hey masterkain, I hope it gets in soon.

Please sign in to comment.
Something went wrong with that request. Please try again.