diff --git a/app/controllers/public/comment_controller.rb b/app/controllers/public/comment_controller.rb index c36b594..35b8b09 100644 --- a/app/controllers/public/comment_controller.rb +++ b/app/controllers/public/comment_controller.rb @@ -57,7 +57,7 @@ class CommentController < ApplicationController return end - if @comment.article.moderate_comments? && !(@comment.author && @comment.author_id == @comment.article.author_id) + if @comment.need_moderation? @comment.created_at = Time.now ApproveComment.create!(:requestor => @comment.author, :target => profile, :comment_attributes => @comment.attributes.to_json) diff --git a/app/models/comment.rb b/app/models/comment.rb index 2c5ad4b..47920ae 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -255,4 +255,8 @@ class Comment < ActiveRecord::Base plugins.dispatch(:comment_marked_as_ham, self) end + def need_moderation? + article.moderate_comments? && (author.nil? || article.author != author) + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 3330354..3d727d4 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -550,6 +550,49 @@ class CommentTest < ActiveSupport::TestCase SpammerLogger.clean_log end + should 'not need moderation if article is not moderated' do + article = Article.new + comment = Comment.new(:article => article) + + assert !comment.need_moderation? + end + + should 'not need moderation if the comment author is the article author' do + author = Person.new + article = Article.new + + article.stubs(:author).returns(author) + article.moderate_comments = true + + comment = Comment.new(:article => article) + comment.stubs(:author).returns(author) + + assert !comment.need_moderation? + end + + should 'need moderation if article is moderated and the comment has no author' do + article = Article.new + article.stubs(:moderate_comments?).returns(true) + + comment = Comment.new(:article => article) + + assert comment.need_moderation? + end + + should 'need moderation if article is moderated and the comment author is different from article author' do + article_author = Person.new + comment_author = Person.new + + article = Article.new + article.stubs(:author).returns(article_author) + article.stubs(:moderate_comments?).returns(true) + + comment = Comment.new(:article => article) + comment.stubs(:author).returns(comment_author) + + assert comment.need_moderation? + end + private def create_comment(args = {}) -- libgit2 0.21.2