2009-03-20 11:07:49 -04:00
|
|
|
require 'models/topic'
|
|
|
|
|
|
|
|
class Reply < Topic
|
|
|
|
validate :errors_on_empty_content
|
2013-05-01 20:10:06 -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
|
2013-05-01 20:10:06 -04:00
|
|
|
validate :check_content_mismatch, on: :create
|
|
|
|
validate :check_wrong_update, on: :update
|
2009-03-20 11:07:49 -04:00
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_empty_title
|
2010-05-08 16:27:49 -04:00
|
|
|
errors[:title] << "is Empty" unless title && title.size > 0
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def errors_on_empty_content
|
2010-05-08 16:27:49 -04:00
|
|
|
errors[:content] << "is Empty" unless content && content.size > 0
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_content_mismatch
|
2010-05-08 16:27:49 -04:00
|
|
|
if title && content && content == "Mismatch"
|
2009-03-20 11:07:49 -04:00
|
|
|
errors[:title] << "is Content Mismatch"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def title_is_wrong_create
|
2010-05-08 16:27:49 -04:00
|
|
|
errors[:title] << "is Wrong Create" if title && title == "Wrong Create"
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
|
2009-03-21 15:05:09 -04:00
|
|
|
def check_wrong_update
|
2010-05-08 16:27:49 -04:00
|
|
|
errors[:title] << "is Wrong Update" if title && title == "Wrong Update"
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
end
|