From 7c930d32042fd3c335f868dc14f7a44ad784e66e Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 6 May 2024 10:23:25 +0800 Subject: [PATCH] DEV: Handle empty strings for `small_links` migration Follow up to 105b001d9f662333ff2925514c3c2e930fb2de00 --- .../settings/0003-migrate-small-links-setting.js | 2 ++ .../0003_migrate_small_links_setting_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/migrations/settings/0003-migrate-small-links-setting.js b/migrations/settings/0003-migrate-small-links-setting.js index f1be7f8..0f149b8 100644 --- a/migrations/settings/0003-migrate-small-links-setting.js +++ b/migrations/settings/0003-migrate-small-links-setting.js @@ -31,6 +31,8 @@ export default function migrate(settings, helpers) { }); settings.set("small_links", newSmallLinks); + } else if (oldSmallLinks?.trim() === "") { + settings.set("small_links", []); } return settings; diff --git a/spec/migrations/0003_migrate_small_links_setting_spec.rb b/spec/migrations/0003_migrate_small_links_setting_spec.rb index 919a2ac..96f7d41 100644 --- a/spec/migrations/0003_migrate_small_links_setting_spec.rb +++ b/spec/migrations/0003_migrate_small_links_setting_spec.rb @@ -3,6 +3,19 @@ RSpec.describe "0003-migrate-small-links-setting migration" do let!(:theme) { upload_theme_component } + it "should handle an empty string for old setting" do + theme.theme_settings.create!( + name: "small_links", + theme:, + data_type: ThemeSetting.types[:string], + value: " ", + ) + + run_theme_migration(theme, "0003-migrate-small-links-setting") + + expect(theme.settings[:small_links].value).to eq([]) + end + it "should set target property to `_blank` if previous target component is not valid or empty" do theme.theme_settings.create!( name: "small_links",