A platform for community discussion. Free, open, simple.
FIX: Update themes javascript cache after running themes migrations (#25562)
Alan Guo Xiang Tand460229ed890
diff --git a/app/models/theme.rb b/app/models/theme.rbindex 607f354b955..a771e7a2669 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -172,7 +172,9 @@ class Theme < ActiveRecord::Basejs_compiler = ThemeJavascriptCompiler.new(id, name)js_compiler.append_tree(all_extra_js)settings_hash = build_settings_hash+js_compiler.prepend_settings(settings_hash) if settings_hash.present?+javascript_cache || build_javascript_cachejavascript_cache.update!(content: js_compiler.content, source_map: js_compiler.source_map)else@@ -880,6 +882,7 @@ class Theme < ActiveRecord::Baseendself.reload+ self.update_javascript_cache!endif start_transactiondiff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rbindex 014878be669..fe1babece39 100644--- a/spec/models/theme_spec.rb+++ b/spec/models/theme_spec.rb@@ -1095,11 +1095,42 @@ HTML)end+ it "updates the theme's javascript cache after running migration" do+ theme.set_field(target: :extra_js, name: "test.js.es6", value: "const hello = 'world';")+ theme.save!++ expect(theme.javascript_cache.content).to include('"list_setting":"aa,bb"')++ settings_field.update!(value: <<~YAML)+ integer_setting: 1+ list_setting:+ default: aa|bb+ type: list+ YAML++ migration_field.update!(value: <<~JS)+ export default function migrate(settings) {+ settings.set("list_setting", "zz|aa");+ return settings;+ }+ JS++ theme.reload+ theme.migrate_settings++ setting_record = theme.theme_settings.where(name: "list_setting").first++ expect(setting_record.data_type).to eq(ThemeSetting.types[:list])+ expect(setting_record.value).to eq("zz|aa")+ expect(theme.javascript_cache.content).to include('"list_setting":"zz|aa"')+ end+it "allows changing a setting's type" dotheme.update_setting(:list_setting, "zz,aa")theme.save!setting_record = theme.theme_settings.where(name: "list_setting").first+expect(setting_record.data_type).to eq(ThemeSetting.types[:string])expect(setting_record.value).to eq("zz,aa")@@ -1109,12 +1140,14 @@ HTMLdefault: aa|bbtype: listYAML+migration_field.update!(value: <<~JS)export default function migrate(settings) {settings.set("list_setting", "zz|aa");return settings;}JS+theme.reloadtheme.migrate_settings