FIX: Harmonise category body class generation on server/client (#16967)

The server-side implementation had unintentionally changed to include `-{id}` at the end of the body class name. This change meant that the JS client was unaware of the class, and didn't remove it when navigating away from the category page.

This commit fixes the server-side implementation to match the client
This commit is contained in:
David Taylor 2022-06-01 18:18:20 +01:00 committed by GitHub
parent 08a8c27f16
commit 333c58dd05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -181,7 +181,7 @@ module ApplicationHelper
result = ApplicationHelper.extra_body_classes.to_a
if @category && @category.url.present?
result << "category-#{@category.url.sub(/^\/c\//, '').gsub(/\//, '-')}"
result << "category-#{@category.slug_path.join('-')}"
end
if current_user.present? &&

View File

@ -941,4 +941,15 @@ RSpec.describe ListController do
expect(response.parsed_body['topic_list']['topics'].map { |t| t['id'] }).to contain_exactly(topic2.id)
end
end
describe "body class" do
it "pre-renders the correct body class for categories" do
c = Fabricate(:category, slug: 'myparentslug')
sub_c = Fabricate(:category, parent_category: c, slug: 'mychildslug')
get "/c/#{c.slug}/#{sub_c.slug}/#{sub_c.id}"
expect(response.body).to have_tag "body", with: { class: "category-myparentslug-mychildslug" }
end
end
end