diff --git a/app/models/theme.rb b/app/models/theme.rb index 29d3a4566fe..a644266c5a1 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -6,7 +6,7 @@ require "json_schemer" class Theme < ActiveRecord::Base include GlobalPath - BASE_COMPILER_VERSION = 77 + BASE_COMPILER_VERSION = 78 class SettingsMigrationError < StandardError end diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb index 6be9efb600d..53e2d4a896c 100644 --- a/app/models/theme_field.rb +++ b/app/models/theme_field.rb @@ -664,6 +664,8 @@ class ThemeField < ActiveRecord::Base name: ThemeField.scss_fields + ThemeField.html_fields, ) ) + elsif translation_field? + return theme.theme_fields.where(target_id: Theme.targets[:translations]) end ThemeField.none end diff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rb index c28fcebdad4..3ea94529972 100644 --- a/spec/models/theme_field_spec.rb +++ b/spec/models/theme_field_spec.rb @@ -595,6 +595,57 @@ HTML expect(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") + end end describe "prefix injection" do