Permalink
Browse files

Merge pull request #4828 from railsaholic/fix_error_message

fix has_one, has_many restrict error message
  • Loading branch information...
2 parents 6da8ec1 + 907d193 commit 403cce77f19bc6c2a3d8acaf547991078a540eaf @josevalim josevalim committed Feb 1, 2012
@@ -74,7 +74,8 @@ def define_restrict_dependency_method
if dependent_restrict_raises?
raise ActiveRecord::DeleteRestrictionError.new(name)
else
- errors.add(:base, :restrict_dependent_destroy, :model => name.to_s.singularize)
+ key = association(name).reflection.macro == :has_one ? "one" : "many"
+ errors.add(:base, :"restrict_dependent_destroy.#{key}", :record => name)
return false
end
end
@@ -10,7 +10,9 @@ en:
messages:
taken: "has already been taken"
record_invalid: "Validation failed: %{errors}"
- restrict_dependent_destroy: "Cannot delete record because dependent %{model} exists"
+ restrict_dependent_destroy:
+ one: "Cannot delete record because a dependent %{record} exists"
+ many: "Cannot delete record because dependent %{record} exist"
# Append your own errors here or at the model/attributes scope.
# You can define own errors for models or model attributes.
@@ -1171,7 +1171,7 @@ def test_restrict_when_dependent_restrict_raises_config_set_to_false
assert !firm.errors.empty?
- assert_equal "Cannot delete record because dependent company exists", firm.errors[:base].first
+ assert_equal "Cannot delete record because dependent companies exist", firm.errors[:base].first
assert RestrictedFirm.exists?(:name => 'restrict')
assert firm.companies.exists?(:name => 'child')
ensure
@@ -184,7 +184,7 @@ def test_dependence_with_restrict_with_dependent_restrict_raises_config_set_to_f
firm.destroy
assert !firm.errors.empty?
- assert_equal "Cannot delete record because dependent account exists", firm.errors[:base].first
+ assert_equal "Cannot delete record because a dependent account exists", firm.errors[:base].first
assert RestrictedFirm.exists?(:name => 'restrict')
assert firm.account.present?
ensure

0 comments on commit 403cce7

Please sign in to comment.