FIX: Refactor commit a8c3ca, add test

FIX: Refactor commit a8c3ca, add test

From ad665b901a6c419c3026ae455fa6a98b4adc14dd Mon Sep 17 00:00:00 2001
From: Penar Musaraj <pmusaraj@gmail.com>
Date: Thu, 29 Nov 2018 19:11:32 -0500
Subject: [PATCH] FIX: Refactor commit a8c3ca, add test


diff --git a/lib/svg_sprite/svg_sprite.rb b/lib/svg_sprite/svg_sprite.rb
index a651d3c..0a8a7e1 100644
--- a/lib/svg_sprite/svg_sprite.rb
+++ b/lib/svg_sprite/svg_sprite.rb
@@ -287,7 +287,7 @@ Discourse SVG subset of #{fa_license}
     site_setting_icons = []
 
     SiteSetting.settings_hash.select do |key, value|
-      if key.to_s.include?("_icon") && value.present? && value.class == String
+      if key.to_s.include?("_icon") && String === value
         site_setting_icons |= value.split('|')
       end
     end
@@ -317,7 +317,7 @@ Discourse SVG subset of #{fa_license}
     # Theme.all includes default values
     Theme.all.each do |theme|
       settings = theme.cached_settings.each do |key, value|
-        if key.to_s.include?("_icon") && value.present? && value.class == String
+        if key.to_s.include?("_icon") && String === value
           theme_icon_settings |= value.split('|')
         end
       end
diff --git a/spec/components/svg_sprite/svg_sprite_spec.rb b/spec/components/svg_sprite/svg_sprite_spec.rb
index 7636158..1d0fad9 100644
--- a/spec/components/svg_sprite/svg_sprite_spec.rb
+++ b/spec/components/svg_sprite/svg_sprite_spec.rb
@@ -83,6 +83,10 @@ describe SvgSprite do
 
     SiteSetting.svg_icon_subset = nil
     expect(SvgSprite.all_icons).not_to include("drafting-compass")
+
+    # does not fail on non-string setting
+    SiteSetting.svg_icon_subset = false
+    expect(SvgSprite.all_icons).to be_truthy
   end
 
   it 'includes icons from plugin registry' do

GitHub

2 Likes