mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 00:38:04 +08:00
FIX: Preload parent categories for sidebar (#25726)
When "lazy load categories" is enabled, only the categories present in the sidebar are preloaded. This is insufficient because the parent categories are necessary too for the sidebar to be rendered properly.
This commit is contained in:
@ -183,6 +183,40 @@ RSpec.describe Site do
|
||||
DiscoursePluginRegistry.clear_modifiers!
|
||||
end
|
||||
end
|
||||
|
||||
context "with lazy loaded categories enabled" do
|
||||
fab!(:user)
|
||||
|
||||
before { SiteSetting.lazy_load_categories_groups = "#{Group::AUTO_GROUPS[:everyone]}" }
|
||||
|
||||
it "does not return any categories for anonymous users" do
|
||||
site = Site.new(Guardian.new)
|
||||
|
||||
expect(site.categories).to eq([])
|
||||
end
|
||||
|
||||
it "returns only sidebar categories and their parent categories" do
|
||||
parent_category = Fabricate(:category)
|
||||
category.update!(parent_category: parent_category)
|
||||
Fabricate(:category_sidebar_section_link, linkable: category, user: user)
|
||||
|
||||
site = Site.new(Guardian.new(user))
|
||||
|
||||
expect(site.categories.map { |c| c[:id] }).to contain_exactly(
|
||||
parent_category.id,
|
||||
category.id,
|
||||
)
|
||||
end
|
||||
|
||||
it "returns only visible sidebar categories" do
|
||||
Fabricate(:category_sidebar_section_link, linkable: category, user: user)
|
||||
category.update!(read_restricted: true)
|
||||
|
||||
site = Site.new(Guardian.new(user))
|
||||
|
||||
expect(site.categories).to eq([])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "omits groups user can not see" do
|
||||
|
Reference in New Issue
Block a user