2008-01-18 02:31:37 -05:00
|
|
|
require 'models/topic'
|
2005-11-04 00:46:28 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Reply < Topic
|
2010-01-17 18:08:19 -05:00
|
|
|
scope :base
|
2008-04-30 01:25:52 -04:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
|
2009-07-15 16:22:25 -04:00
|
|
|
belongs_to :topic_with_primary_key, :class_name => "Topic", :primary_key => "title", :foreign_key => "parent_title", :counter_cache => "replies_count"
|
2006-03-18 15:25:50 -05:00
|
|
|
has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
|
2004-12-09 07:50:18 -05:00
|
|
|
|
2009-12-31 21:20:38 -05:00
|
|
|
attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read, :parent_title
|
|
|
|
end
|
|
|
|
|
|
|
|
class WrongReply < Reply
|
2004-12-09 07:50:18 -05:00
|
|
|
validate :errors_on_empty_content
|
2009-09-08 11:10:14 -04:00
|
|
|
validate :title_is_wrong_create, :on => :create
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
validate :check_empty_title
|
2009-09-08 11:10:14 -04:00
|
|
|
validate :check_content_mismatch, :on => :create
|
|
|
|
validate :check_wrong_update, :on => :update
|
2009-03-21 15:05:09 -04:00
|
|
|
|
|
|
|
def check_empty_title
|
2009-03-19 19:28:59 -04:00
|
|
|
errors[:title] << "Empty" unless attribute_present?("title")
|
2004-12-09 07:50:18 -05:00
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-12-09 07:50:18 -05:00
|
|
|
def errors_on_empty_content
|
2009-03-19 19:28:59 -04:00
|
|
|
errors[:content] << "Empty" unless attribute_present?("content")
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_content_mismatch
|
2004-11-23 20:04:44 -05:00
|
|
|
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
|
2009-03-19 19:28:59 -04:00
|
|
|
errors[:title] << "is Content Mismatch"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-12-09 07:50:18 -05:00
|
|
|
def title_is_wrong_create
|
2009-03-19 19:28:59 -04:00
|
|
|
errors[:title] << "is Wrong Create" if attribute_present?("title") && title == "Wrong Create"
|
2004-12-09 07:50:18 -05:00
|
|
|
end
|
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_wrong_update
|
2009-03-19 19:28:59 -04:00
|
|
|
errors[:title] << "is Wrong Update" if attribute_present?("title") && title == "Wrong Update"
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|
2004-12-12 13:12:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class SillyReply < Reply
|
2006-03-09 12:23:57 -05:00
|
|
|
belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
|
2005-11-04 00:46:28 -05:00
|
|
|
end
|
2008-12-31 04:43:13 -05:00
|
|
|
|
|
|
|
module Web
|
|
|
|
class Reply < Web::Topic
|
|
|
|
belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true, :class_name => 'Web::Topic'
|
|
|
|
end
|
2009-09-08 11:10:14 -04:00
|
|
|
end
|