diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index 9ec8725d4db4f..8d115074909c7 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -68,8 +68,9 @@ def human_attribute_name(attribute, options = {}) defaults << options[:default] if options[:default] defaults << MISSING_TRANSLATION unless raise_on_missing + capitalize_missing_translation = options.delete(:_capitalize) { true } translation = I18n.translate(defaults.shift, count: 1, raise: raise_on_missing, **options, default: defaults) - translation = attribute.humanize if translation == MISSING_TRANSLATION + translation = attribute.humanize(capitalize: capitalize_missing_translation) if translation == MISSING_TRANSLATION translation end end diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index f8dbc95b40e09..208f76033408f 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -18,7 +18,7 @@ def handle_dependency when :restrict_with_error unless empty? - record = owner.class.human_attribute_name(reflection.name).downcase + record = owner.class.human_attribute_name(reflection.name, _capitalize: false) owner.errors.add(:base, :'restrict_dependent_destroy.has_many', record: record) throw(:abort) end diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index 5e1b523dbefec..50d1bcbb410f4 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -13,7 +13,7 @@ def handle_dependency when :restrict_with_error if load_target - record = owner.class.human_attribute_name(reflection.name).downcase + record = owner.class.human_attribute_name(reflection.name, _capitalize: false) owner.errors.add(:base, :'restrict_dependent_destroy.has_one', record: record) throw(:abort) end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 424d32b9f9347..3cc78c2441bc2 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -2006,7 +2006,7 @@ def test_restrict_with_error def test_restrict_with_error_with_locale I18n.backend = I18n::Backend::Simple.new - I18n.backend.store_translations "en", activerecord: { attributes: { restricted_with_error_firm: { companies: "client companies" } } } + I18n.backend.store_translations "en", activerecord: { attributes: { restricted_with_error_firm: { companies: "LLC companies" } } } firm = RestrictedWithErrorFirm.create!(name: "restrict") firm.companies.create(name: "child") @@ -2016,7 +2016,7 @@ def test_restrict_with_error_with_locale assert_not_empty firm.errors - assert_equal "Cannot delete record because dependent client companies exist", firm.errors[:base].first + assert_equal "Cannot delete record because dependent LLC companies exist", firm.errors[:base].first assert RestrictedWithErrorFirm.exists?(name: "restrict") assert firm.companies.exists?(name: "child") ensure diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 0da12625c05d0..a2cd052a9a5b4 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -243,7 +243,7 @@ def test_restrict_with_error def test_restrict_with_error_with_locale I18n.backend = I18n::Backend::Simple.new - I18n.backend.store_translations "en", activerecord: { attributes: { restricted_with_error_firm: { account: "firm account" } } } + I18n.backend.store_translations "en", activerecord: { attributes: { restricted_with_error_firm: { account: "LLC account" } } } firm = RestrictedWithErrorFirm.create!(name: "restrict") firm.create_account(credit_limit: 10) @@ -252,7 +252,7 @@ def test_restrict_with_error_with_locale firm.destroy assert_not_empty firm.errors - assert_equal "Cannot delete record because a dependent firm account exists", firm.errors[:base].first + assert_equal "Cannot delete record because a dependent LLC account exists", firm.errors[:base].first assert RestrictedWithErrorFirm.exists?(name: "restrict") assert_predicate firm.account, :present? ensure