0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/spec/db/migrate/20251024015907_populate_image_quality_setting_spec.rb
David Taylor aa6a0f733c
DEV: Force new_site? to true in PopulateImageQualitySetting fresh-install spec (#39972)
Previously, the "is a no-op on fresh installs" example relied on the
test database being less than an hour old.

This change forces `schema_migration_details.created_at` to `NOW()`, so
that the spec will be reliable.
2026-05-13 11:51:09 +01:00

48 lines
1.6 KiB
Ruby
Vendored

# frozen_string_literal: true
require Rails.root.join("db/migrate/20251024015907_populate_image_quality_setting.rb")
RSpec.describe PopulateImageQualitySetting do
before do
@original_verbose = ActiveRecord::Migration.verbose
ActiveRecord::Migration.verbose = false
end
after do
ActiveRecord::Migration.verbose = @original_verbose
Discourse.clear_site_creation_date_cache
end
it "is a no-op on fresh installs" do
DB.exec("UPDATE schema_migration_details SET created_at = NOW()")
Discourse.clear_site_creation_date_cache
expect { PopulateImageQualitySetting.new.up }.not_to change {
DB.query_single("SELECT count(*) FROM site_settings WHERE name = 'image_quality'").first
}
end
context "when the site is an existing install" do
before do
DB.exec("UPDATE schema_migration_details SET created_at = NOW() - INTERVAL '2 hours'")
Discourse.clear_site_creation_date_cache
end
it "maps recompress_original_jpg_quality into image_quality buckets" do
mapping = { 60 => 50, 75 => 70, 99 => 90, 100 => 100 }
mapping.each do |current, expected|
DB.exec(<<~SQL)
INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
VALUES ('recompress_original_jpg_quality', 1, #{current}, NOW(), NOW())
ON CONFLICT (name) DO UPDATE SET value = EXCLUDED.value
SQL
PopulateImageQualitySetting.new.up
row = DB.query("SELECT value FROM site_settings WHERE name = 'image_quality'")[0]
expect(row.value.to_i).to eq(expected)
end
end
end
end