diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index c0ce7ec..f845e52 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -301,6 +301,19 @@ class CommentTest < ActiveSupport::TestCase assert result[1].replies.empty? end + should "return activities comments when some comment on thread is spam" do + person = fast_create(Person) + a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') + c0 = Comment.create(:source => a, :body => 'Root comment', :author => person) + c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person) + spam = Comment.create(:spam => true, :reply_of_id => c0.id, :source => a, :body => 'spam', :author => person) + c2 = Comment.create(:reply_of_id => spam.id, :source => a, :body => 'c2', :author => person) + result = a.activity.comments_as_thread + assert_equal c0, result[0] + assert_equal [c1], result[0].replies + assert_equal c2, result[1] + end + should 'provide author url for authenticated user' do author = Person.new author.expects(:url).returns('http://blabla.net/author') diff --git a/vendor/plugins/action_tracker_has_comments/init.rb b/vendor/plugins/action_tracker_has_comments/init.rb index e5a7abf..2f0375e 100644 --- a/vendor/plugins/action_tracker_has_comments/init.rb +++ b/vendor/plugins/action_tracker_has_comments/init.rb @@ -16,7 +16,13 @@ Rails.configuration.to_prepare do self.comments.each do |c| c.replies = [] result[c.id] ||= c - c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c + if c.reply_of_id.nil? + root << c + elsif result[c.reply_of_id] + result[c.reply_of_id].replies << c + else # Comment is a reply but the reply is not being displayed - is spam, for example + root << c + end end root end -- libgit2 0.21.2