diff options
author | Manoj <manoj.mk27@gmail.com> | 2012-02-01 23:55:01 +0530 |
---|---|---|
committer | Manoj <manoj.mk27@gmail.com> | 2012-02-01 23:58:20 +0530 |
commit | 907d19343ebe2f0807337e0fda83b23076f87383 (patch) | |
tree | b7c989d3754933a83fa8f7f9576ae09c71357a14 /activerecord | |
parent | 049dc500b632ca1a05d41a0c5454946f24d15035 (diff) | |
download | rails-907d19343ebe2f0807337e0fda83b23076f87383.tar.gz rails-907d19343ebe2f0807337e0fda83b23076f87383.tar.bz2 rails-907d19343ebe2f0807337e0fda83b23076f87383.zip |
fix has_one, has_many restrict error message
Diffstat (limited to 'activerecord')
4 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index c3fa4a05fd..0410c3a3c1 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -74,7 +74,8 @@ module ActiveRecord::Associations::Builder 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 diff --git a/activerecord/lib/active_record/locale/en.yml b/activerecord/lib/active_record/locale/en.yml index 8892f7ef2f..896132d566 100644 --- a/activerecord/lib/active_record/locale/en.yml +++ b/activerecord/lib/active_record/locale/en.yml @@ -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. diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ab1e821aab..f2af892840 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1171,7 +1171,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 37be6a279d..c2548e33c5 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -184,7 +184,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase 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 |