diff --git a/app/models/comment.rb b/app/models/comment.rb index 6bb9bec..a984540 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -147,10 +147,14 @@ class Comment < ActiveRecord::Base def self.as_thread result = {} root = [] - all.each do |c| + order(:id).each do |c| c.replies = [] result[c.id] ||= c - c.reply_of_id.nil? ? root << c : result[c.reply_of_id].replies << c + if result[c.reply_of_id] + result[c.reply_of_id].replies << c + else + root << c + end end root end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index cbab01e..e06f424 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -536,6 +536,15 @@ class CommentTest < ActiveSupport::TestCase assert_equal c, SpamNotification.marked_as_ham end + should 'ignore spam when constructing threads' do + original = create_comment + response = create_comment(:reply_of_id => original.id) + original.spam! + + assert_equivalent [response], Comment.without_spam.as_thread + end + + should 'store User-Agent' do c = Comment.new(:user_agent => 'foo') assert_equal 'foo', c.user_agent -- libgit2 0.21.2