A platform for community discussion. Free, open, simple.
FIX: Recompile theme translations when fallback data changes (#24371)
David Tayloreda79186eefa
diff --git a/app/models/theme.rb b/app/models/theme.rbindex 29d3a4566fe..a644266c5a1 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -6,7 +6,7 @@ require "json_schemer"class Theme < ActiveRecord::Baseinclude GlobalPath- BASE_COMPILER_VERSION = 77+ BASE_COMPILER_VERSION = 78class SettingsMigrationError < StandardErrorenddiff --git a/app/models/theme_field.rb b/app/models/theme_field.rbindex 6be9efb600d..53e2d4a896c 100644--- a/app/models/theme_field.rb+++ b/app/models/theme_field.rb@@ -664,6 +664,8 @@ class ThemeField < ActiveRecord::Basename: ThemeField.scss_fields + ThemeField.html_fields,))+ elsif translation_field?+ return theme.theme_fields.where(target_id: Theme.targets[:translations])endThemeField.noneenddiff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rbindex c28fcebdad4..3ea94529972 100644--- a/spec/models/theme_field_spec.rb+++ b/spec/models/theme_field_spec.rb@@ -595,6 +595,57 @@ HTMLexpect(fr1.javascript_cache.content).to include("helloworld")expect(fr1.javascript_cache.content).to include("enval1")end++ it "is recreated when data changes" do+ t = Fabricate(:theme)+ t.set_field(+ target: "translations",+ name: "fr",+ value: { fr: { mykey: "initial value" } }.deep_stringify_keys.to_yaml,+ )+ t.save!++ field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")+ expect(field.javascript_cache.content).to include("initial value")++ t.set_field(+ target: "translations",+ name: "fr",+ value: { fr: { mykey: "new value" } }.deep_stringify_keys.to_yaml,+ )+ t.save!++ field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")+ expect(field.javascript_cache.reload.content).to include("new value")+ end++ it "is recreated when fallback data changes" do+ t = Fabricate(:theme)+ t.set_field(+ target: "translations",+ name: "fr",+ value: { fr: {} }.deep_stringify_keys.to_yaml,+ )+ t.set_field(+ target: "translations",+ name: "en",+ value: { en: { myotherkey: "initial value" } }.deep_stringify_keys.to_yaml,+ )+ t.save!++ field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")+ expect(field.javascript_cache.content).to include("initial value")++ t.set_field(+ target: "translations",+ name: "en",+ value: { en: { myotherkey: "new value" } }.deep_stringify_keys.to_yaml,+ )+ t.save!++ field = t.theme_fields.find_by(target_id: Theme.targets[:translations], name: "fr")+ expect(field.javascript_cache.reload.content).to include("new value")+ endenddescribe "prefix injection" do