FIX: Serialize parent categories first (#24530)

The parent category needs to be serialized before the child category
because they are parsed in order. Otherwise the client will not build
the parent-child relationship correctly.
This commit is contained in:
Bianca Nenciu 2023-11-23 19:03:05 +02:00 committed by GitHub
parent 2228f75645
commit 012541b045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -78,7 +78,7 @@ class TopicList
def categories def categories
@categories ||= @categories ||=
topics.map { |t| [t.category, t.category&.parent_category] }.uniq.flatten.compact topics.map { |t| [t.category&.parent_category, t.category] }.uniq.flatten.compact
end end
def load_topics def load_topics

View File

@ -239,9 +239,9 @@ RSpec.describe ListController do
expect(response.parsed_body["topic_list"]["topics"].length).to eq(1) 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"]["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"].length).to eq(2)
expect( expect(response.parsed_body["topic_list"]["categories"].map { |c| c["id"] }).to eq(
response.parsed_body["topic_list"]["categories"].map { |c| c["id"] }, [category.id, subcategory.id],
).to contain_exactly(category.id, subcategory.id) )
end end
it "does not return categories if not true" do it "does not return categories if not true" do