Commit 70c90e476a2a263639d13654564b8ea9db30a911
1 parent
9a383b33
Exists in
master
and in
28 other branches
Fix: comments list when there is spam on thread
(ActionItem2918)
Showing
2 changed files
with
20 additions
and
1 deletions
Show diff stats
test/unit/comment_test.rb
... | ... | @@ -301,6 +301,19 @@ class CommentTest < ActiveSupport::TestCase |
301 | 301 | assert result[1].replies.empty? |
302 | 302 | end |
303 | 303 | |
304 | + should "return activities comments when some comment on thread is spam" do | |
305 | + person = fast_create(Person) | |
306 | + a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body') | |
307 | + c0 = Comment.create(:source => a, :body => 'Root comment', :author => person) | |
308 | + c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person) | |
309 | + spam = Comment.create(:spam => true, :reply_of_id => c0.id, :source => a, :body => 'spam', :author => person) | |
310 | + c2 = Comment.create(:reply_of_id => spam.id, :source => a, :body => 'c2', :author => person) | |
311 | + result = a.activity.comments_as_thread | |
312 | + assert_equal c0, result[0] | |
313 | + assert_equal [c1], result[0].replies | |
314 | + assert_equal c2, result[1] | |
315 | + end | |
316 | + | |
304 | 317 | should 'provide author url for authenticated user' do |
305 | 318 | author = Person.new |
306 | 319 | author.expects(:url).returns('http://blabla.net/author') | ... | ... |
vendor/plugins/action_tracker_has_comments/init.rb
... | ... | @@ -16,7 +16,13 @@ Rails.configuration.to_prepare do |
16 | 16 | self.comments.each do |c| |
17 | 17 | c.replies = [] |
18 | 18 | result[c.id] ||= c |
19 | - c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c | |
19 | + if c.reply_of_id.nil? | |
20 | + root << c | |
21 | + elsif result[c.reply_of_id] | |
22 | + result[c.reply_of_id].replies << c | |
23 | + else # Comment is a reply but the reply is not being displayed - is spam, for example | |
24 | + root << c | |
25 | + end | |
20 | 26 | end |
21 | 27 | root |
22 | 28 | end | ... | ... |