A platform for community discussion. Free, open, simple.
FIX: One-by-off error in topic show action (#13183)
Bianca Nenciuc247776c65dd
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex a7814a22991..4e66f3e7889 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -128,7 +128,7 @@ class TopicsController < ApplicationControllerendpage = params[:page]- if (page < 0) || ((page - 1) * @topic_view.chunk_size > @topic_view.topic.highest_post_number)+ if (page < 0) || ((page - 1) * @topic_view.chunk_size >= @topic_view.topic.highest_post_number)raise Discourse::NotFoundenddiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 79f6be9be59..f72e7d833f7 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -2157,6 +2157,28 @@ RSpec.describe TopicsController doget "/t/#{topic.slug}/#{topic.id}/#{post_number}.json"expect(response.status).to eq(200)expect(extract_post_stream).to eq(@post_ids[-2..-1])++ TopicView.stubs(:chunk_size).returns(3)++ get "/t/#{topic.slug}/#{topic.id}.json", params: { page: 1 }+ expect(response.status).to eq(200)+ expect(extract_post_stream).to eq(@post_ids[0..2])++ get "/t/#{topic.slug}/#{topic.id}.json", params: { page: 2 }+ expect(response.status).to eq(200)+ expect(extract_post_stream).to eq(@post_ids[3..3])++ get "/t/#{topic.slug}/#{topic.id}.json", params: { page: 3 }+ expect(response.status).to eq(404)++ TopicView.stubs(:chunk_size).returns(4)++ get "/t/#{topic.slug}/#{topic.id}.json", params: { page: 1 }+ expect(response.status).to eq(200)+ expect(extract_post_stream).to eq(@post_ids[0..3])++ get "/t/#{topic.slug}/#{topic.id}.json", params: { page: 2 }+ expect(response.status).to eq(404)endend