diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-10 21:42:03 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-10 21:42:03 +0100 |
commit | 0cffe1b316b010b53dd5b5c6a63e4082d23e216d (patch) | |
tree | 05c419c6428a2bcdc083a3f2682856fa07473d76 /actionview/test | |
parent | efa445c7b5fe17b4f1a2aeb6ad5dcac464dbe9d6 (diff) | |
parent | 82aab15dac7b15f7d19ef9f931068e8777c17e55 (diff) | |
download | rails-0cffe1b316b010b53dd5b5c6a63e4082d23e216d.tar.gz rails-0cffe1b316b010b53dd5b5c6a63e4082d23e216d.tar.bz2 rails-0cffe1b316b010b53dd5b5c6a63e4082d23e216d.zip |
Merge pull request #20638 from jaimeiniesta/locale-aware-pluralize-helper
Pass the current locale to Inflector from the pluralize text helper.
Diffstat (limited to 'actionview/test')
-rw-r--r-- | actionview/test/template/text_helper_test.rb | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb index fae1965ffa..fb98ac6330 100644 --- a/actionview/test/template/text_helper_test.rb +++ b/actionview/test/template/text_helper_test.rb @@ -379,24 +379,36 @@ class TextHelperTest < ActionView::TestCase assert_equal("1.25 counts", pluralize('1.25', "count")) assert_equal("1.0 count", pluralize('1.0', "count")) assert_equal("1.00 count", pluralize('1.00', "count")) - assert_equal("2 counters", pluralize(2, "count", "counters")) - assert_equal("0 counters", pluralize(nil, "count", "counters")) + assert_equal("2 counters", pluralize(2, "count", plural: "counters")) + assert_equal("0 counters", pluralize(nil, "count", plural: "counters")) assert_equal("2 people", pluralize(2, "person")) assert_equal("10 buffaloes", pluralize(10, "buffalo")) assert_equal("1 berry", pluralize(1, "berry")) assert_equal("12 berries", pluralize(12, "berry")) end - def test_pluralization_with_locale - ActiveSupport::Inflector.inflections(:de) do |inflect| - inflect.plural(/(person)$/i, '\1en') - inflect.singular(/(person)en$/i, '\1') - end + def test_localized_pluralization + old_locale = I18n.locale + + begin + I18n.locale = :de + + ActiveSupport::Inflector.inflections(:de) do |inflect| + inflect.irregular 'region', 'regionen' + end - assert_equal("2 People", pluralize(2, "Person", locale: :en)) - assert_equal("2 Personen", pluralize(2, "Person", locale: :de)) + assert_equal("1 region", pluralize(1, "region")) + assert_equal("2 regionen", pluralize(2, "region")) + assert_equal("2 regions", pluralize(2, "region", locale: :en)) + ensure + I18n.locale = old_locale + end + end - ActiveSupport::Inflector.inflections(:de).clear + def test_deprecated_plural_as_positional_argument + assert_deprecated do + pluralize(2, 'count', 'counters') + end end def test_cycle_class |