Commit 252ec20a19d4019ca95061c946cc531308f0c150
1 parent
d7430804
Exists in
master
and in
29 other branches
Ignore spam when constructing threads
ActionItem2306
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
app/models/comment.rb
| ... | ... | @@ -147,10 +147,14 @@ class Comment < ActiveRecord::Base |
| 147 | 147 | def self.as_thread |
| 148 | 148 | result = {} |
| 149 | 149 | root = [] |
| 150 | - all.each do |c| | |
| 150 | + order(:id).each do |c| | |
| 151 | 151 | c.replies = [] |
| 152 | 152 | result[c.id] ||= c |
| 153 | - c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c | |
| 153 | + if result[c.reply_of_id] | |
| 154 | + result[c.reply_of_id].replies << c | |
| 155 | + else | |
| 156 | + root << c | |
| 157 | + end | |
| 154 | 158 | end |
| 155 | 159 | root |
| 156 | 160 | end | ... | ... |
test/unit/comment_test.rb
| ... | ... | @@ -536,6 +536,15 @@ class CommentTest < ActiveSupport::TestCase |
| 536 | 536 | assert_equal c, SpamNotification.marked_as_ham |
| 537 | 537 | end |
| 538 | 538 | |
| 539 | + should 'ignore spam when constructing threads' do | |
| 540 | + original = create_comment | |
| 541 | + response = create_comment(:reply_of_id => original.id) | |
| 542 | + original.spam! | |
| 543 | + | |
| 544 | + assert_equivalent [response], Comment.without_spam.as_thread | |
| 545 | + end | |
| 546 | + | |
| 547 | + | |
| 539 | 548 | should 'store User-Agent' do |
| 540 | 549 | c = Comment.new(:user_agent => 'foo') |
| 541 | 550 | assert_equal 'foo', c.user_agent | ... | ... |