discourse/spec/db/migrate/20250714010001_backfill_themeable_site_settings_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

38 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require Rails.root.join("db/migrate/20250714010001_backfill_themeable_site_settings.rb")
RSpec.describe BackfillThemeableSiteSettings do
fab!(:theme_1, :theme)
fab!(:theme_2, :theme)
fab!(:theme_3) { Fabricate(:theme, component: true) }
before do
@original_verbose = ActiveRecord::Migration.verbose
ActiveRecord::Migration.verbose = false
end
after { ActiveRecord::Migration.verbose = @original_verbose }
it "works" do
DB.exec(
"INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
VALUES ('enable_welcome_banner', :data_type, :value, NOW(), NOW())",
data_type: SiteSettings::TypeSupervisor.types[:bool],
value: "t",
)
BackfillThemeableSiteSettings.new.up
# This count includes the system themes theme, but not the component.
expect(ThemeSiteSetting.where(name: "enable_welcome_banner").count).to eq(4)
# Don't insert any record if the site setting was never changed from the default.
expect(ThemeSiteSetting.where(name: "search_experience").count).to eq(0)
# Make sure the data type + value are the same as the site setting.
expect(
ThemeSiteSetting.find_by(name: "enable_welcome_banner", theme_id: theme_1.id),
).to have_attributes(data_type: SiteSettings::TypeSupervisor.types[:bool], value: "t")
end
end