Skip to content

A platform for community discussion. Free, open, simple.

FIX: Include more_topic_url in the response to /categories_and_{latest, top} (#21738)

Sérgio Saquetim6a65fa982df8
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 0bf524f9652..bb289d1fd39 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -327,11 +327,16 @@ class CategoriesController < ApplicationController
if topics_filter == :latest
result.topic_list = TopicQuery.new(current_user, topic_options).list_latest
+ result.topic_list.more_topics_url =
+ url_for(
+ public_send("latest_path", sort: topic_options[:order] == "created" ? :created : nil),
+ )
elsif topics_filter == :top
result.topic_list =
TopicQuery.new(current_user, topic_options).list_top_for(
SiteSetting.top_page_default_timeframe.to_sym,
)
+ result.topic_list.more_topics_url = url_for(public_send("top_path"))
end
render_serialized(result, CategoryAndTopicListsSerializer, root: false)
diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb
index 8666391b98a..bb5759f813a 100644
--- a/spec/requests/categories_controller_spec.rb
+++ b/spec/requests/categories_controller_spec.rb
@@ -244,6 +244,23 @@ RSpec.describe CategoriesController do
[topic1.id, topic3.id, topic2.id],
)
end
+
+ it "does not include the sort parameter in more_topics_url" do
+ # we need to create more topics for more_topics_url to be serialized
+ SiteSetting.categories_topics = 5
+ Fabricate.times(
+ 5,
+ :topic,
+ category: category,
+ created_at: 1.day.ago,
+ bumped_at: 1.day.ago,
+ )
+
+ get "/categories_and_latest.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["topic_list"]["more_topics_url"]).to start_with("/latest")
+ expect(response.parsed_body["topic_list"]["more_topics_url"]).not_to include("sort")
+ end
end
context "when order is set to created" do
@@ -258,6 +275,23 @@ RSpec.describe CategoriesController do
[topic3.id, topic2.id, topic1.id],
)
end
+
+ it "includes the sort parameter in more_topics_url" do
+ # we need to create more topics for more_topics_url to be serialized
+ SiteSetting.categories_topics = 5
+ Fabricate.times(
+ 5,
+ :topic,
+ category: category,
+ created_at: 1.day.ago,
+ bumped_at: 1.day.ago,
+ )
+
+ get "/categories_and_latest.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["topic_list"]["more_topics_url"]).to start_with("/latest")
+ expect(response.parsed_body["topic_list"]["more_topics_url"]).to include("sort=created")
+ end
end
end
@@ -885,6 +919,25 @@ RSpec.describe CategoriesController do
).not_to include(uncategorized.id)
end
+ it "includes more_topics_url in the response to /categories_and_latest" do
+ SiteSetting.categories_topics = 5
+
+ get "/categories_and_latest.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["topic_list"]["more_topics_url"]).to start_with("/latest")
+ end
+
+ it "includes more_topics_url in the response to /categories_and_top" do
+ SiteSetting.categories_topics = 5
+
+ Fabricate.times(10, :topic, category: category, like_count: 1000, posts_count: 100)
+ TopTopic.refresh!
+
+ get "/categories_and_top.json"
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["topic_list"]["more_topics_url"]).to start_with("/top")
+ end
+
describe "Showing top topics from private categories" do
it "returns the top topic from the private category when the user is a member" do
restricted_group = Fabricate(:group)