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