FIX: Preload sidebar categories when lazy loading categories (#25332)

This fixes a bug where the sidebar categories would not be loaded when
the categories were lazy loaded because the sidebar uses the preloaded
category list, which was empty.
This commit is contained in:
Bianca Nenciu
2024-02-02 10:35:15 +02:00
committed by GitHub
parent e071b74a79
commit 1d160702ad
3 changed files with 42 additions and 9 deletions

View File

@ -131,12 +131,34 @@ RSpec.describe SiteSerializer do
expect(serialized[:shared_drafts_category_id]).to eq(nil)
end
it "does not include categories if lazy_load_categories" do
SiteSetting.lazy_load_categories_groups = "#{Group::AUTO_GROUPS[:everyone]}"
context "with lazy loaded categories enabled" do
fab!(:user)
let(:guardian) { Guardian.new(user) }
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
before { SiteSetting.lazy_load_categories_groups = "#{Group::AUTO_GROUPS[:everyone]}" }
expect(serialized[:categories]).to eq(nil)
it "categories does not include any categories for anonymous users" do
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:categories]).to eq(nil)
end
it "categories include only sidebar categories" do
Fabricate(:category_sidebar_section_link, linkable: category, user: user)
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:categories].map { |c| c[:id] }).to contain_exactly(category.id)
end
it "categories include only visible sidebar categories" do
Fabricate(:category_sidebar_section_link, linkable: category, user: user)
category.update!(read_restricted: true)
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(serialized[:categories]).to eq(nil)
end
end
describe "#anonymous_default_navigation_menu_tags" do