mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 03:43:54 +08:00
Inside `type objects` we accepted upload URLs and converted them into IDs, but we did not update the original object to have an ID. Only on consuming should we turn the ID into a URL. For normal front-end consumers, object upload fields should still be URLs. Backend consumers should expect upload IDs. <img width="2295" height="1263" alt="Screenshot 2026-05-20 at 12 19 23" src="https://github.com/user-attachments/assets/20d411c4-1570-45fc-96c8-02f2b1b3639d" />
72 lines
2.2 KiB
Ruby
Vendored
72 lines
2.2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe "tasks/site_settings" do
|
|
describe "site_settings:normalize_object_uploads" do
|
|
fab!(:theme)
|
|
fab!(:upload)
|
|
|
|
it "normalizes upload URLs in object settings" do
|
|
SiteSetting.create!(
|
|
name: "ui_cards_setting",
|
|
data_type: SiteSettings::TypeSupervisor.types[:objects],
|
|
value: JSON.generate([{ "title" => "Site card", "image" => upload.url }]),
|
|
)
|
|
|
|
theme.set_field(target: :settings, name: "yaml", value: <<~YAML)
|
|
cards:
|
|
type: objects
|
|
default: []
|
|
schema:
|
|
name: card
|
|
identifier: title
|
|
properties:
|
|
title:
|
|
type: string
|
|
required: true
|
|
image:
|
|
type: upload
|
|
YAML
|
|
theme.save!
|
|
|
|
ThemeSetting.create!(
|
|
theme:,
|
|
name: "cards",
|
|
data_type: ThemeSetting.types[:objects],
|
|
json_value: [{ "title" => "Theme card", "image" => upload.url }],
|
|
)
|
|
|
|
output = capture_stdout { invoke_rake_task("site_settings:normalize_object_uploads") }
|
|
|
|
expect(output).to include("Changed: 2")
|
|
expect(JSON.parse(SiteSetting.find_by(name: "ui_cards_setting").value)).to eq(
|
|
[{ "title" => "Site card", "image" => upload.id }],
|
|
)
|
|
expect(ThemeSetting.find_by(name: "cards").json_value).to eq(
|
|
[{ "title" => "Theme card", "image" => upload.id }],
|
|
)
|
|
end
|
|
|
|
it "does not persist changes in dry run mode" do
|
|
SiteSetting.create!(
|
|
name: "ui_cards_setting",
|
|
data_type: SiteSettings::TypeSupervisor.types[:objects],
|
|
value: JSON.generate([{ "title" => "Site card", "image" => upload.url }]),
|
|
)
|
|
|
|
previous_dry_run = ENV["DRY_RUN"]
|
|
ENV["DRY_RUN"] = "1"
|
|
begin
|
|
output = capture_stdout { invoke_rake_task("site_settings:normalize_object_uploads") }
|
|
|
|
expect(output).to include("Would normalize site setting ui_cards_setting")
|
|
expect(output).to include("Changed: 1")
|
|
ensure
|
|
ENV["DRY_RUN"] = previous_dry_run
|
|
end
|
|
|
|
expect(JSON.parse(SiteSetting.find_by(name: "ui_cards_setting").value)).to eq(
|
|
[{ "title" => "Site card", "image" => upload.url }],
|
|
)
|
|
end
|
|
end
|
|
end
|