diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2019-03-11 21:41:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 21:41:30 +0100 |
commit | cab396f4238997421181057645ab13e552881208 (patch) | |
tree | 6a5f2410a1a09538719eab7e002afa74911d2c4c /activesupport | |
parent | 3a42c2305eccb8d54e66c76eb2ae4eacfd81f941 (diff) | |
parent | 818437c3664039f7038364910fc4ac80450f36a2 (diff) | |
download | rails-cab396f4238997421181057645ab13e552881208.tar.gz rails-cab396f4238997421181057645ab13e552881208.tar.bz2 rails-cab396f4238997421181057645ab13e552881208.zip |
Merge pull request #35572 from sharang-d/tests-for-transliterate-locale-arg
Add test for 'ActiveSupport::Inflector.transliterate'
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/inflector/transliterate.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 6 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 6 | ||||
-rw-r--r-- | activesupport/test/transliterate_test.rb | 6 |
4 files changed, 19 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 09e6cbeaaf..fe778ff0e7 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -90,7 +90,7 @@ module ActiveSupport # def parameterize(string, separator: "-", preserve_case: false, locale: nil) # Replace accented chars with their ASCII equivalents. - parameterized_string = transliterate(string, locale) + parameterized_string = transliterate(string, locale: locale) # Turn unwanted chars into the separator. parameterized_string.gsub!(/[^a-z0-9\-_]+/i, separator) diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 2468fe3603..4ffa33aa61 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -206,6 +206,12 @@ class StringInflectionsTest < ActiveSupport::TestCase end end + def test_parameterize_with_locale + word = "Fünf autos" + I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } }) + assert_equal("fuenf-autos", word.parameterize(locale: :de)) + end + def test_humanize UnderscoreToHuman.each do |underscore, human| assert_equal(human, underscore.humanize) diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index c3e1faff5d..ddf765a220 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -304,6 +304,12 @@ class InflectorTest < ActiveSupport::TestCase end end + def test_parameterize_with_locale + word = "Fünf autos" + I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } }) + assert_equal("fuenf-autos", ActiveSupport::Inflector.parameterize(word, locale: :de)) + end + def test_classify ClassNameToTableName.each do |class_name, table_name| assert_equal(class_name, ActiveSupport::Inflector.classify(table_name)) diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb index 7d19447598..9e29a93ea0 100644 --- a/activesupport/test/transliterate_test.rb +++ b/activesupport/test/transliterate_test.rb @@ -30,6 +30,12 @@ class TransliterateTest < ActiveSupport::TestCase I18n.locale = default_locale end + def test_transliterate_respects_the_locale_argument + char = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS + I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } }) + assert_equal "ue", ActiveSupport::Inflector.transliterate(char, locale: :de) + end + def test_transliterate_should_allow_a_custom_replacement_char assert_equal "a*b", ActiveSupport::Inflector.transliterate("a索b", "*") end |