Post#approve!: signal errors with invalid object instead of exception.

This commit is contained in:
evazion
2017-04-03 13:45:17 -05:00
parent db0bcf08b9
commit 70a7f77a48
4 changed files with 12 additions and 9 deletions

View File

@@ -322,7 +322,7 @@ class Post < ActiveRecord::Base
end
def approve!(approver = CurrentUser.user)
approvals.create!(user: approver)
approvals.create(user: approver)
end
def approved_by?(user)

View File

@@ -14,6 +14,10 @@ class PostApproval < ActiveRecord::Base
errors.add(:post, "is locked and cannot be approved")
end
if post.status == "active"
errors.add(:post, "is already active and cannot be approved")
end
if post.uploader == user
errors.add(:base, "You cannot approve a post you uploaded")
end