1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix bug with parametrize when locale is passed

Also add tests for parametrize and transliterate
This commit is contained in:
Sharang Dashputre 2019-03-12 00:39:58 +05:30
parent 878e98091d
commit 818437c366
4 changed files with 19 additions and 1 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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))

View file

@ -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