Extract compound conditional to a method (#579)

This commit is contained in:
Arun Kumar 2018-07-15 17:02:27 -05:00 committed by Ben Halpern
parent 35eddd5131
commit e950028f1d

View file

@ -115,9 +115,10 @@ class Reaction < ApplicationRecord
end
def permissions
if category == "vomit" || category == "thumbsdown"
errors.add(:category, "is not valid.") unless user.has_role?(:trusted)
if negative_reaction_from_untrusted_user?
errors.add(:category, "is not valid.")
end
if reactable_type == "Article" && !reactable.published
errors.add(:reactable_id, "is not valid.")
end
@ -129,4 +130,12 @@ class Reaction < ApplicationRecord
reactable.update_column(:positive_reactions_count, reactable.reactions.where("points > ?", 0).size)
end
end
def negative_reaction_from_untrusted_user?
negative? && !user.trusted
end
def negative?
category == "vomit" || category == "thumbsdown"
end
end