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
|
|
|
|
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"
|
2009-12-31 21:20:38 -05:00
|
|
|
end
|
|
|
|
|
2011-01-09 12:13:05 -05:00
|
|
|
class UniqueReply < Reply
|
2013-05-18 04:12:46 -04:00
|
|
|
belongs_to :topic, :foreign_key => 'parent_id', :counter_cache => true
|
2011-01-09 12:13:05 -05:00
|
|
|
validates_uniqueness_of :content, :scope => 'parent_id'
|
|
|
|
end
|
|
|
|
|
|
|
|
class SillyUniqueReply < UniqueReply
|
|
|
|
end
|
|
|
|
|
2009-12-31 21:20:38 -05:00
|
|
|
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
|
2010-05-21 10:20:56 -04:00
|
|
|
validate :check_author_name_is_secret, :on => :special_case
|
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
|
2010-05-10 05:28:38 -04:00
|
|
|
|
2010-05-21 10:20:56 -04:00
|
|
|
def check_author_name_is_secret
|
|
|
|
errors[:author_name] << "Invalid" unless author_name == "secret"
|
2010-05-10 05:28:38 -04: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
|