diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 05583e520c0..338b7069055 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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? && diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb index c73ec252f21..890b8b9c07e 100644 --- a/spec/requests/list_controller_spec.rb +++ b/spec/requests/list_controller_spec.rb @@ -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