More PR updates based on feedback

More PR updates based on feedback

  • Use a category serializer for the subcategory_list
  • Don’t include the subcategory_list param if empty
  • For the spec check for the subcategory by id
  • Fix spec to account for param not present when empty
diff --git a/app/serializers/category_detailed_serializer.rb b/app/serializers/category_detailed_serializer.rb
index 9de920b..1349cd4 100644
--- a/app/serializers/category_detailed_serializer.rb
+++ b/app/serializers/category_detailed_serializer.rb
@@ -10,15 +10,20 @@ class CategoryDetailedSerializer < BasicCategorySerializer
              :topics_year,
              :topics_all_time,
              :is_uncategorized,
-             :subcategory_ids,
-             :subcategory_list
+             :subcategory_ids
 
   has_many :displayable_topics, serializer: ListableTopicSerializer, embed: :objects, key: :topics
 
+  has_many :subcategory_list, serializer: CategoryDetailedSerializer, embed: :objects, key: :subcategory_list
+
   def include_displayable_topics?
     displayable_topics.present?
   end
 
+  def include_subcategory_list?
+    subcategory_list.present?
+  end
+
   def is_uncategorized
     object.id == SiteSetting.uncategorized_category_id
   end
diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb
index c6f4ccb..2067279 100644
--- a/spec/requests/categories_controller_spec.rb
+++ b/spec/requests/categories_controller_spec.rb
@@ -82,11 +82,11 @@ describe CategoriesController do
       category_list = response.parsed_body["category_list"]
 
       subcategories_for_category = category_list["categories"][1]["subcategory_list"]
-      expect(subcategories_for_category.count).to eq(0)
+      expect(subcategories_for_category).to eq(nil)
     end
 
     it 'returns the right subcategory response with permission' do
-      subcategory = Fabricate(:category, name: "subcat", user: admin, parent_category: category)
+      subcategory = Fabricate(:category, user: admin, parent_category: category)
 
       sign_in(user)
 
@@ -99,7 +99,7 @@ describe CategoriesController do
       subcategories_for_category = category_list["categories"][1]["subcategory_list"]
       expect(subcategories_for_category.count).to eq(1)
       expect(subcategories_for_category.first["parent_category_id"]).to eq(category.id)
-      expect(subcategories_for_category.first["name"]).to eq("subcat")
+      expect(subcategories_for_category.first["id"]).to eq(subcategory.id)
     end
 
     it 'does not return subcategories without query param' do

GitHub sha: 8dff48dcf199542e6e4f7ec5283b195376441608