diff options
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/company.rb | 9 | ||||
-rw-r--r-- | activerecord/test/models/company_in_module.rb | 9 | ||||
-rw-r--r-- | activerecord/test/models/reply.rb | 20 |
3 files changed, 24 insertions, 14 deletions
diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index eb68153bbe..4c2514b0b3 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -145,10 +145,13 @@ class Account < ActiveRecord::Base true end + validate :check_empty_credit_limit + protected - def validate - errors.add_on_empty "credit_limit" - end + + def check_empty_credit_limit + errors.add_on_empty "credit_limit" + end private diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb index 3c34efbe16..8b84c2fb5e 100644 --- a/activerecord/test/models/company_in_module.rb +++ b/activerecord/test/models/company_in_module.rb @@ -54,10 +54,13 @@ module MyApplication i.belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm' end + validate :check_empty_credit_limit + protected - def validate - errors.add_on_empty "credit_limit" - end + + def check_empty_credit_limit + errors.add_on_empty "credit_limit" + end end end end diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb index 1c990acab6..616c07687c 100644 --- a/activerecord/test/models/reply.rb +++ b/activerecord/test/models/reply.rb @@ -11,26 +11,30 @@ class Reply < Topic attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read - def validate - errors.add("title", "Empty") unless attribute_present? "title" + validate :check_empty_title + validate_on_create :check_content_mismatch + validate_on_update :check_wrong_update + + def check_empty_title + errors[:title] << "Empty" unless attribute_present?("title") end def errors_on_empty_content - errors.add("content", "Empty") unless attribute_present? "content" + errors[:content] << "Empty" unless attribute_present?("content") end - def validate_on_create + def check_content_mismatch if attribute_present?("title") && attribute_present?("content") && content == "Mismatch" - errors.add("title", "is Content Mismatch") + errors[:title] << "is Content Mismatch" end end def title_is_wrong_create - errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create" + errors[:title] << "is Wrong Create" if attribute_present?("title") && title == "Wrong Create" end - def validate_on_update - errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update" + def check_wrong_update + errors[:title] << "is Wrong Update" if attribute_present?("title") && title == "Wrong Update" end end |