models: drop unnecessary presence validations.

In rails 5, belongs_to associations automatically validate that the
associated item is present, meaning that we don't need to validate these
things manually any more.
This commit is contained in:
evazion
2019-08-04 14:40:37 -05:00
parent 7c8c4e9f82
commit a926b162be
16 changed files with 11 additions and 36 deletions

View File

@@ -13,9 +13,8 @@ class ForumPost < ApplicationRecord
after_create :update_topic_updated_at_on_create
after_update :update_topic_updated_at_on_update_for_original_posts
after_destroy :update_topic_updated_at_on_destroy
validates_presence_of :body, :creator_id
validates_presence_of :body
validate :validate_topic_is_unlocked
validate :topic_id_not_invalid
validate :topic_is_not_restricted, :on => :create
before_destroy :validate_topic_is_unlocked
after_save :delete_topic_if_original_post
@@ -144,13 +143,6 @@ class ForumPost < ApplicationRecord
end
end
def topic_id_not_invalid
if topic_id && !topic
errors[:base] << "Topic ID is invalid"
return false
end
end
def topic_is_not_restricted
if topic && !topic.visible?(creator)
errors[:topic] << "is restricted"