discourse/spec/models/theme_setting_spec.rb
Alan Guo Xiang Tan 9f884cdaab
DEV: Introduce experimental type: objects theme setting (#25538)
Why this change?

This commit introduces an experimental `type: objects` theme setting
which will allow theme developers to store a collection of objects as
JSON in the database. Currently, the feature is still in development and
this commit is simply setting up the ground work for us to introduce the
feature in smaller pieces.

What does this change do?

1. Adds a `json_value` column as `jsonb` data type to the `theme_settings` table.
2. Adds a `experimental_objects_type_for_theme_settings` site setting to
   determine whether `ThemeSetting` records of with the `objects` data
   type can be created.
3. Updates `ThemeSettingsManager` to support read/write access from the
   `ThemeSettings#json_value` column.
2024-02-08 10:20:59 +08:00

27 lines
944 B
Ruby

# frozen_string_literal: true
RSpec.describe ThemeSetting do
fab!(:theme)
context "for validations" do
it "should be invalid when setting data_type to objects and `experimental_objects_type_for_theme_settings` is disabled" do
SiteSetting.experimental_objects_type_for_theme_settings = false
theme_setting =
ThemeSetting.new(name: "test", data_type: ThemeSetting.types[:objects], theme:)
expect(theme_setting.valid?).to eq(false)
expect(theme_setting.errors[:data_type]).to contain_exactly("is not included in the list")
end
it "should be valid when setting data_type to objects and `experimental_objects_type_for_theme_settings` is enabled" do
SiteSetting.experimental_objects_type_for_theme_settings = true
theme_setting =
ThemeSetting.new(name: "test", data_type: ThemeSetting.types[:objects], theme:)
expect(theme_setting.valid?).to eq(true)
end
end
end