A platform for community discussion. Free, open, simple.
FIX: Set has_children correctly in Category.preload_user_fields! (#26327)
Daniel Waterworthd52abe232447
diff --git a/app/models/category.rb b/app/models/category.rbindex 66458783069..1dae5366199 100644--- a/app/models/category.rb+++ b/app/models/category.rb@@ -241,7 +241,7 @@ class Category < ActiveRecord::Base# Categories with childrenwith_children =Category- .secured(@guardian)+ .secured(guardian).where(parent_category_id: category_ids).pluck(:parent_category_id).to_setdiff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rbindex d8948831207..e27d9520046 100644--- a/spec/requests/categories_controller_spec.rb+++ b/spec/requests/categories_controller_spec.rb@@ -1140,6 +1140,26 @@ RSpec.describe CategoriesController doexpect(category["permission"]).to eq(CategoryGroup.permission_types[:full])expect(category["has_children"]).to eq(true)end++ context "with a read restricted child category" do+ before_all { subcategory.update!(read_restricted: true) }++ it "indicates to an admin that the category has a child" do+ sign_in(admin)++ get "/categories/find.json", params: { ids: [category.id] }+ category = response.parsed_body["categories"].first+ expect(category["has_children"]).to eq(true)+ end++ it "indicates to a normal user that the category has no child" do+ sign_in(user)++ get "/categories/find.json", params: { ids: [category.id] }+ category = response.parsed_body["categories"].first+ expect(category["has_children"]).to eq(false)+ end+ endenddescribe "#search" do