Files
nairobi/lib/merged_comment_tree.rb
Javi Martín dbcc5fb724 Use AR relations when merging comments
Using arrays made it difficult to order by more than one field (like the
`most_voted` scope does), and so we were ordering by `confidence_score`
and ignoring the `created_at` column.

Using an AR relation makes it easy to reuse the existing `most_voted`
scope.

This change has one side effect: now comments with equal votes are
ordered in descending order instead of having no specific order. That
means flaky specs which failed sometimes because they assumed comments
were ordered by date are now always green.

I've also re-added the `oldest` scope removed in 792b15b thinking it was
removed because using it with arrays was too hard.
2019-05-29 20:50:53 +02:00

14 lines
299 B
Ruby

class MergedCommentTree < CommentTree
attr_reader :commentables
def initialize(commentables, page, order = "confidence_score")
@commentables = commentables
super(commentables.first, page, order)
end
def base_comments
Comment.where(commentable: commentables.flatten)
end
end