A platform for community discussion. Free, open, simple.
FIX: Use filtered posts when determining the next page
David Taylorbe1510b09d53
diff --git a/lib/topic_view.rb b/lib/topic_view.rbindex 0f26832202b..b95254d14ae 100644--- a/lib/topic_view.rb+++ b/lib/topic_view.rb@@ -152,7 +152,7 @@ class TopicViewdef next_page@next_page ||= begin- if last_post && (@topic.highest_post_number > last_post.post_number)+ if last_post && highest_post_number && (highest_post_number > last_post.post_number)@page + 1endenddiff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rbindex ce1f0e844ae..2d6948c6b89 100644--- a/spec/components/topic_view_spec.rb+++ b/spec/components/topic_view_spec.rb@@ -48,6 +48,11 @@ describe TopicView doexpect(tv.filtered_post_ids).to eq([post.id, post2.id])end+ it "returns nil for next_page" do+ tv = TopicView.new(topic.id, evil_trout)+ expect(tv.next_page).to eq(nil)+ end+describe "when an ignored user made the original post" dolet!(:post) { Fabricate(:post, topic: topic, user: user) }@@ -245,22 +250,16 @@ describe TopicView doenddescribe "#next_page" do- let(:p2) { stub(post_number: 2) }- let(:topic) do- topic = create_topic- topic.stubs(:highest_post_number).returns(5)- topic- end+ let!(:post) { Fabricate(:post, topic: topic, user: user) }+ let!(:post2) { Fabricate(:post, topic: topic, user: user) }+ let!(:post3) { Fabricate(:post, topic: topic, user: user) }before do- TopicView.any_instance.expects(:find_topic).with(1234).returns(topic)- TopicView.any_instance.stubs(:filter_posts)- TopicView.any_instance.stubs(:last_post).returns(p2)TopicView.stubs(:chunk_size).returns(2)endit "should return the next page" do- expect(TopicView.new(1234, user).next_page).to eql(2)+ expect(TopicView.new(topic.id, user).next_page).to eql(2)endend