Fix ActiveSupport::Inflector.humanize(nil)

This commit is contained in:
James Robinson 2023-07-25 16:47:47 +01:00
parent 06e8bb5b4c
commit 016b81f0b2
3 changed files with 9 additions and 1 deletions

@ -1,3 +1,7 @@
* Fix `ActiveSupport::Inflector.humanize(nil)` raising ``NoMethodError: undefined method `end_with?' for nil:NilClass``.
*James Robinson*
* Don't show secrets for `ActiveSupport::KeyGenerator#inspect`.
Before:

@ -139,7 +139,7 @@ def humanize(lower_case_and_underscored_word, capitalize: true, keep_id_suffix:
result.tr!("_", " ")
result.lstrip!
if !keep_id_suffix && lower_case_and_underscored_word.end_with?("_id")
if !keep_id_suffix && lower_case_and_underscored_word&.end_with?("_id")
result.delete_suffix!(" id")
end

@ -380,6 +380,10 @@ def test_humanize
end
end
def test_humanize_nil
assert_equal("", ActiveSupport::Inflector.humanize(nil))
end
def test_humanize_without_capitalize
UnderscoreToHumanWithoutCapitalize.each do |underscore, human|
assert_equal(human, ActiveSupport::Inflector.humanize(underscore, capitalize: false))