2009-03-20 11:07:49 -04:00
|
|
|
require 'models/topic'
|
|
|
|
|
|
|
|
class Reply < Topic
|
|
|
|
validate :errors_on_empty_content
|
2009-09-08 11:10:14 -04:00
|
|
|
validate :title_is_wrong_create, :on => :create
|
2009-03-20 11:07:49 -04: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
|
|
|
|
2009-03-20 11:07:49 -04:00
|
|
|
attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
|
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_empty_title
|
2009-03-20 11:07:49 -04:00
|
|
|
errors[:title] << "Empty" unless attribute_present?("title")
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors_on_empty_content
|
|
|
|
errors[:content] << "Empty" unless attribute_present?("content")
|
|
|
|
end
|
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_content_mismatch
|
2009-03-20 11:07:49 -04:00
|
|
|
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
|
|
|
|
errors[:title] << "is Content Mismatch"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def title_is_wrong_create
|
|
|
|
errors[:title] << "is Wrong Create" if attribute_present?("title") && title == "Wrong Create"
|
|
|
|
end
|
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_wrong_update
|
2009-03-20 11:07:49 -04:00
|
|
|
errors[:title] << "is Wrong Update" if attribute_present?("title") && title == "Wrong Update"
|
|
|
|
end
|
|
|
|
end
|