From 0ea9d8164b8f5a45b0c636a654b732018f6cb1e6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 26 Nov 2024 02:19:20 -0500 Subject: [PATCH] Remove `body_class_string` helper (#33072) --- app/controllers/application_controller.rb | 5 ----- app/helpers/application_helper.rb | 2 +- spec/helpers/application_helper_spec.rb | 20 +++++++++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d493bd43bf..7a858ed059 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,7 +22,6 @@ class ApplicationController < ActionController::Base helper_method :use_seamless_external_login? helper_method :sso_account_settings helper_method :limited_federation_mode? - helper_method :body_class_string helper_method :skip_csrf_meta_tags? rescue_from ActionController::ParameterMissing, Paperclip::AdapterRegistry::NoHandlerError, with: :bad_request @@ -158,10 +157,6 @@ class ApplicationController < ActionController::Base current_user.setting_theme end - def body_class_string - @body_classes || '' - end - def respond_with_error(code) respond_to do |format| format.any { render "errors/#{code}", layout: 'error', status: code, formats: [:html] } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3d5025724f..9861ee7e8e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -143,7 +143,7 @@ module ApplicationHelper end def body_classes - output = body_class_string.split + output = [] output << content_for(:body_classes) output << "theme-#{current_theme.parameterize}" output << 'system-font' if current_account&.user&.setting_system_font_ui diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 557d08e851..942cc5103c 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -5,12 +5,20 @@ require 'rails_helper' RSpec.describe ApplicationHelper do describe 'body_classes' do context 'with a body class string from a controller' do - before { helper.extend controller_helpers } + before do + user = Fabricate :user + user.settings['web.use_system_font'] = true + user.settings['web.reduce_motion'] = true + user.save - it 'uses the controller body classes in the result' do + helper.extend controller_helpers + end + + it 'uses the current theme and user settings classes in the result' do expect(helper.body_classes) - .to match(/modal-layout compose-standalone/) - .and match(/theme-default/) + .to match(/theme-default/) + .and match(/system-font/) + .and match(/reduce-motion/) end it 'includes values set via content_for' do @@ -24,10 +32,8 @@ RSpec.describe ApplicationHelper do def controller_helpers Module.new do - def body_class_string = 'modal-layout compose-standalone' - def current_account - @current_account ||= Fabricate(:account) + @current_account ||= Fabricate(:account, user: User.last) end def current_theme = 'default'