Froze rails gems
[depot.git] / vendor / rails / activerecord / test / models / reply.rb
1 require 'models/topic'
2
3 class Reply < Topic
4 named_scope :base
5
6 belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
7 has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
8
9 validate :errors_on_empty_content
10 validate_on_create :title_is_wrong_create
11
12 attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
13
14 def validate
15 errors.add("title", "Empty") unless attribute_present? "title"
16 end
17
18 def errors_on_empty_content
19 errors.add("content", "Empty") unless attribute_present? "content"
20 end
21
22 def validate_on_create
23 if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
24 errors.add("title", "is Content Mismatch")
25 end
26 end
27
28 def title_is_wrong_create
29 errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
30 end
31
32 def validate_on_update
33 errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update"
34 end
35 end
36
37 class SillyReply < Reply
38 belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
39 end