discourse/spec/models/theme_site_setting_spec.rb
Jarek Radosz 71834c898f
DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073)
Co-authored-by: Loïc Guitaut <loic@discourse.org>
2025-10-06 16:11:01 +02:00

71 lines
1.8 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ThemeSiteSetting do
fab!(:theme_1, :theme)
fab!(:theme_2, :theme)
fab!(:theme_site_setting_1) do
Fabricate(
:theme_site_setting_with_service,
theme: theme_1,
name: "enable_welcome_banner",
value: false,
)
end
fab!(:theme_site_setting_2) do
Fabricate(
:theme_site_setting_with_service,
theme: theme_1,
name: "search_experience",
value: "search_field",
)
end
describe ".generate_theme_map" do
it "returns a map of theme ids mapped to theme site settings, using site setting defaults if the setting records do not exist" do
expect(ThemeSiteSetting.generate_theme_map).to include(
{
theme_1.id => {
enable_welcome_banner: false,
search_experience: "search_field",
},
theme_2.id => {
enable_welcome_banner: true,
search_experience: "search_icon",
},
},
)
end
context "when skipping redis" do
before { GlobalSetting.skip_redis = true }
after { GlobalSetting.skip_redis = false }
it "returns {}" do
expect(ThemeSiteSetting.generate_theme_map).to eq({})
end
end
context "when skipping db" do
before { GlobalSetting.skip_db = true }
after { GlobalSetting.skip_db = false }
it "returns {}" do
expect(ThemeSiteSetting.generate_theme_map).to eq({})
end
end
context "when the table doesn't exist yet, in case of migrations" do
before do
ActiveRecord::Base
.connection
.stubs(:table_exists?)
.with(ThemeSiteSetting.table_name)
.returns(false)
end
it "returns {}" do
expect(ThemeSiteSetting.generate_theme_map).to eq({})
end
end
end
end