FIX: Fix safe mode regression

FIX: Fix safe mode regression

Follow up from a48731e

diff --git a/app/models/theme.rb b/app/models/theme.rb
index df91e6e..39c2b9a 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -134,10 +134,10 @@ class Theme < ActiveRecord::Base
 
       all_ids = [parent, *components]
 
-      enabled_ids = Theme.where(id: all_ids).includes(:remote_theme)
-        .select(&:enabled?).pluck(:id)
+      disabled_ids = Theme.where(id: all_ids).includes(:remote_theme)
+        .reject(&:enabled?).pluck(:id)
 
-      all_ids & enabled_ids # Maintain ordering using intersection
+      all_ids - disabled_ids
     end
   end
 
diff --git a/spec/components/stylesheet/manager_spec.rb b/spec/components/stylesheet/manager_spec.rb
index 1942647..00df90f 100644
--- a/spec/components/stylesheet/manager_spec.rb
+++ b/spec/components/stylesheet/manager_spec.rb
@@ -15,6 +15,11 @@ describe Stylesheet::Manager do
     expect(link).not_to eq("")
   end
 
+  it "still returns something for no themes" do
+    link = Stylesheet::Manager.stylesheet_link_tag(:desktop, 'all', [])
+    expect(link).not_to eq("")
+  end
+
   it 'can correctly compile theme css' do
     theme = Fabricate(:theme)
 
diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb
index 7654f9d..17ba4f9 100644
--- a/spec/models/theme_spec.rb
+++ b/spec/models/theme_spec.rb
@@ -65,6 +65,11 @@ describe Theme do
     expect(Theme.transform_ids([theme.id])).to be_empty
   end
 
+  it "#transform_ids works with nil values" do
+    # Used in safe mode
+    expect(Theme.transform_ids([nil])).to eq([nil])
+  end
+
   it "doesn't allow multi-level theme components" do
     grandchild = Fabricate(:theme, user: user)
     grandparent = Fabricate(:theme, user: user)

GitHub sha: 2e48c435

1 Like