diff --git a/app/models/comment.rb b/app/models/comment.rb index 22c9d1f..d8461bb 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -269,4 +269,8 @@ class Comment < ActiveRecord::Base user == profile || user.has_permission?(:moderate_comments, profile) end + def can_be_updated_by?(user) + user.present? && user == author + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 4c3cbf1..aac949f 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -670,6 +670,26 @@ class CommentTest < ActiveSupport::TestCase assert comment.can_be_marked_as_spam_by?(user) end + should 'not be able to update comment without user' do + comment = Comment.new + + assert !comment.can_be_updated_by?(nil) + end + + should 'not be able to update comment' do + user = Person.new + comment = Comment.new + + assert !comment.can_be_updated_by?(user) + end + + should 'be able to update comment if is the author' do + user = Person.new + comment = Comment.new(:author => user) + + assert comment.can_be_updated_by?(user) + end + private def create_comment(args = {}) -- libgit2 0.21.2