diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 67f9b9d3e..f8d3585f3 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -28,7 +28,7 @@ class TopicsController < ApplicationController opts = params.slice(:username_filters, :best_of, :page, :post_number, :posts_before, :posts_after, :best) @topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts) - raise Discourse::NotFound unless @topic_view.posts.present? || (request.format && request.format.json?) + raise Discourse::NotFound if @topic_view.posts.blank? && !(opts[:best].to_i > 0) anonymous_etag(@topic_view.topic) do redirect_to_correct_topic && return if slugs_do_not_match diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 6bad3c1a3..d221035b3 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -177,6 +177,7 @@ class TopicView @index_offset = 0 @posts = @filtered_posts.order('percent_rank asc, sort_order asc').where("post_number > 1") @posts = @posts.includes(:reply_to_user).includes(:topic).joins(:user).limit(max) + @posts = @posts.where('posts.post_type <> ?', Post.types[:moderator_action]) @posts = @posts.to_a @posts.sort!{|a,b| a.post_number <=> b.post_number} @posts diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index 547d1a477..350a36f0b 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -23,11 +23,19 @@ describe TopicView do let!(:p2) { Fabricate(:post, topic: topic, user: coding_horror, percent_rank: 0.5 )} let!(:p3) { Fabricate(:post, topic: topic, user: first_poster, percent_rank: 0 )} - it "it can the best 2 responses" do + it "it can find the best responses" do best2 = TopicView.new(topic.id, nil, best: 2) best2.posts.count.should == 2 best2.posts[0].id.should == p2.id best2.posts[1].id.should == p3.id + + topic.update_status('closed', true, Fabricate(:admin)) + topic.posts.count.should == 4 + + # should not get the status post + best = TopicView.new(topic.id, nil, best: 99) + best.posts.count.should == 2 + end diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index d25f9c7ae..01d9f531d 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -2,8 +2,6 @@ require 'spec_helper' describe TopicsController do - - context 'move_posts' do it 'needs you to be logged in' do lambda { xhr :post, :move_posts, topic_id: 111, title: 'blah', post_ids: [1,2,3] }.should raise_error(Discourse::NotLoggedIn)