Post#approve!: signal errors with invalid object instead of exception.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user