FIX: 'anon' css class is missing for anonymous users

FIX: ‘anon’ css class is missing for anonymous users

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1ee2f33..6009c19 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -114,6 +114,7 @@ module ApplicationHelper
     list << (mobile_device? ? 'mobile-device' : 'not-mobile-device')
     list << 'rtl' if rtl?
     list << text_size_class
+    list << 'anon' unless current_user
     list.join(' ')
   end
 
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 0b1aa0e..594164d 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -148,6 +148,8 @@ describe ApplicationHelper do
   end
 
   describe '#html_classes' do
+    let(:user) { Fabricate(:user) }
+
     it "includes 'rtl' when the I18n.locale is rtl" do
       I18n.stubs(:locale).returns(:he)
       expect(helper.html_classes.split(" ")).to include('rtl')
@@ -159,7 +161,6 @@ describe ApplicationHelper do
     end
 
     it 'includes the user specified text size' do
-      user = Fabricate(:user)
       user.user_option.text_size = "larger"
       user.user_option.save!
       helper.request.env[Auth::DefaultCurrentUserProvider::CURRENT_USER_KEY] = user
@@ -171,6 +172,12 @@ describe ApplicationHelper do
       SiteSetting.default_text_size = "largest"
       expect(helper.html_classes.split(" ")).to include('text-size-largest')
     end
+
+    it "includes 'anon' for anonymous users and excludes when logged in" do
+      expect(helper.html_classes.split(" ")).to include('anon')
+      helper.request.env[Auth::DefaultCurrentUserProvider::CURRENT_USER_KEY] = user
+      expect(helper.html_classes.split(" ")).not_to include('anon')
+    end
   end
 
   describe 'gsub_emoji_to_unicode' do

GitHub sha: 70b56c83

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: