Skip to content

Commit

Permalink
Merge pull request #35572 from sharang-d/tests-for-transliterate-loca…
Browse files Browse the repository at this point in the history
…le-arg

Add test for 'ActiveSupport::Inflector.transliterate'
  • Loading branch information
kaspth committed Mar 11, 2019
2 parents 3a42c23 + 818437c commit cab396f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def transliterate(string, replacement = "?", locale: nil)
#
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)
Expand Down
6 changes: 6 additions & 0 deletions activesupport/test/core_ext/string_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def test_string_parameterized_underscore_preserve_case
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)
Expand Down
6 changes: 6 additions & 0 deletions activesupport/test/inflector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ def test_parameterize_with_multi_character_separator
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))
Expand Down
6 changes: 6 additions & 0 deletions activesupport/test/transliterate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def test_transliterate_should_work_with_custom_i18n_rules_and_uncomposed_utf8
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
Expand Down

0 comments on commit cab396f

Please sign in to comment.