Extract compound conditional to a method (#579)
This commit is contained in:
parent
35eddd5131
commit
e950028f1d
1 changed files with 11 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue