Skip to content

Commit da6a886

Browse files
committed
improve best filter so it properly excludes all admin messages from count as well
1 parent c4d8085 commit da6a886

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

lib/topic_view.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def initialize(topic_id, user=nil, options={})
2525
@filtered_posts = @topic.posts
2626
@filtered_posts = @filtered_posts.with_deleted if user.try(:staff?)
2727
@filtered_posts = @filtered_posts.best_of if options[:best_of].present?
28+
@filtered_posts = @filtered_posts.where('posts.post_type <> ?', Post.types[:moderator_action]) if options[:best].present?
2829

2930
if options[:username_filters].present?
3031
usernames = options[:username_filters].map{|u| u.downcase}
@@ -177,7 +178,6 @@ def filter_best(max)
177178
@index_offset = 0
178179
@posts = @filtered_posts.order('percent_rank asc, sort_order asc').where("post_number > 1")
179180
@posts = @posts.includes(:reply_to_user).includes(:topic).joins(:user).limit(max)
180-
@posts = @posts.where('posts.post_type <> ?', Post.types[:moderator_action])
181181
@posts = @posts.to_a
182182
@posts.sort!{|a,b| a.post_number <=> b.post_number}
183183
@posts

spec/components/topic_view_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
# should not get the status post
3636
best = TopicView.new(topic.id, nil, best: 99)
3737
best.posts.count.should == 2
38+
best.filtered_posts_count.should == 3
3839

3940
end
4041

0 commit comments

Comments
 (0)