FIX: Set has_children correctly in Category.preload_user_fields! (#26327)
This commit is contained in:
parent
4a7e69d8ee
commit
d52abe2324
|
@ -241,7 +241,7 @@ class Category < ActiveRecord::Base
|
|||
# Categories with children
|
||||
with_children =
|
||||
Category
|
||||
.secured(@guardian)
|
||||
.secured(guardian)
|
||||
.where(parent_category_id: category_ids)
|
||||
.pluck(:parent_category_id)
|
||||
.to_set
|
||||
|
|
|
@ -1140,6 +1140,26 @@ RSpec.describe CategoriesController do
|
|||
expect(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
|
||||
end
|
||||
end
|
||||
|
||||
describe "#search" do
|
||||
|
|
Loading…
Reference in New Issue