mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Serialize categories in topic lists (#23597)
At this moment, this feature is under a site setting named
lazy_load_categories.
In the future, categories will no longer be preloaded through site data.
This commit add information about categories in topic list and ensures
that data is used to display topic list items.
Parent categories are serialized too because they are necessary to
render {{category-link}}.
This commit is contained in:
@@ -223,6 +223,38 @@ RSpec.describe ListController do
|
||||
expect(response.body).not_to include(restricted_tag.name)
|
||||
end
|
||||
end
|
||||
|
||||
context "with lazy_load_categories" do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:subcategory) { Fabricate(:category, parent_category: category) }
|
||||
|
||||
before { topic.update!(category: subcategory) }
|
||||
|
||||
it "returns categories and parent categories if true" do
|
||||
SiteSetting.lazy_load_categories = true
|
||||
|
||||
get "/latest.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_list"]["topics"].length).to eq(1)
|
||||
expect(response.parsed_body["topic_list"]["topics"][0]["id"]).to eq(topic.id)
|
||||
expect(response.parsed_body["topic_list"]["categories"].length).to eq(2)
|
||||
expect(
|
||||
response.parsed_body["topic_list"]["categories"].map { |c| c["id"] },
|
||||
).to contain_exactly(category.id, subcategory.id)
|
||||
end
|
||||
|
||||
it "does not return categories if not true" do
|
||||
SiteSetting.lazy_load_categories = false
|
||||
|
||||
get "/latest.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["topic_list"]["topics"].length).to eq(1)
|
||||
expect(response.parsed_body["topic_list"]["topics"][0]["id"]).to eq(topic.id)
|
||||
expect(response.parsed_body["topic_list"]["categories"]).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "categories and X" do
|
||||
|
||||
Reference in New Issue
Block a user