FEATURE: Allow theme settings to request refresh (#15037)

Similar to site settings, adds support for `refresh` option to theme settings.

```yaml
super_feature_enabled:
  type: bool
  default: false
  refresh: true
```
This commit is contained in:
Jarek Radosz
2021-11-22 13:16:56 +01:00
committed by GitHub
parent f43c433d50
commit d91d67a442
5 changed files with 63 additions and 0 deletions

View File

@ -902,4 +902,44 @@ HTML
expect(new_digest).to eq(digest)
end
end
describe "#update_setting" do
it "requests clients to refresh if `refresh: true`" do
theme.set_field(target: :settings, name: "yaml", value: <<~YAML)
super_feature_enabled:
type: bool
default: false
refresh: true
YAML
ThemeSetting.create!(theme: theme, data_type: ThemeSetting.types[:bool], name: "super_feature_enabled")
theme.save!
messages = MessageBus.track_publish do
theme.update_setting(:super_feature_enabled, true)
theme.save!
end.filter { |m| m.channel == "/global/asset-version" }
expect(messages.count).to eq(1)
end
it "does not request clients to refresh if `refresh: false`" do
theme.set_field(target: :settings, name: "yaml", value: <<~YAML)
super_feature_enabled:
type: bool
default: false
refresh: false
YAML
ThemeSetting.create!(theme: theme, data_type: ThemeSetting.types[:bool], name: "super_feature_enabled")
theme.save!
messages = MessageBus.track_publish do
theme.update_setting(:super_feature_enabled, true)
theme.save!
end.filter { |m| m.channel == "/global/asset-version" }
expect(messages.count).to eq(0)
end
end
end