Skip to content

A platform for community discussion. Free, open, simple.

FIX: Components mobile-specific CSS was missing (#12259)

Osama Sayeghc0e2fdd20075
diff --git a/app/models/theme.rb b/app/models/theme.rb
index e23bfbfd4cd..66888135f75 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -356,6 +356,8 @@ class Theme < ActiveRecord::Base
if target == :translations
fields = ThemeField.find_first_locale_fields(theme_ids, I18n.fallbacks[name])
else
+ target = :mobile if target == :mobile_theme
+ target = :desktop if target == :desktop_theme
fields = ThemeField.find_by_theme_ids(theme_ids)
.where(target_id: [Theme.targets[target], Theme.targets[:common]])
fields = fields.where(name: name.to_s) unless name.nil?
diff --git a/spec/components/stylesheet/manager_spec.rb b/spec/components/stylesheet/manager_spec.rb
index d4f935d4173..97ab426f617 100644
--- a/spec/components/stylesheet/manager_spec.rb
+++ b/spec/components/stylesheet/manager_spec.rb
@@ -119,6 +119,17 @@ describe Stylesheet::Manager do
expect(hrefs.count).to eq(3) # theme + child_theme + embedded_scss_child
end
+ it '.stylesheet_details can find components mobile SCSS when target is `:mobile_theme`' do
+ child_with_mobile_scss = Fabricate(:theme, component: true)
+ child_with_mobile_scss.set_field(target: :mobile, name: :scss, value: "body { color: red; }")
+ child_with_mobile_scss.save!
+ theme.add_relative_theme!(:child, child_with_mobile_scss)
+
+ hrefs = Stylesheet::Manager.stylesheet_details(:mobile_theme, 'all', [theme.id])
+ expect(hrefs.find { |h| h[:theme_id] == child_with_mobile_scss.id }).to be_present
+ expect(hrefs.count).to eq(3)
+ end
+
it 'does not output multiple assets for non-theme targets' do
hrefs = Stylesheet::Manager.stylesheet_details(:admin, 'all', [theme.id])
expect(hrefs.count).to eq(1)