From b6f6852bba75071d14da84059485db91ef92afea Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 6 May 2024 12:42:58 +0800 Subject: [PATCH] FIX: Make `getCategoryIdByName` theme migration helper case insensitive (#26878) --- app/services/theme_settings_migrations_runner.rb | 2 +- spec/services/theme_settings_migrations_runner_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/theme_settings_migrations_runner.rb b/app/services/theme_settings_migrations_runner.rb index 223ceea66f3..756e0fcbd07 100644 --- a/app/services/theme_settings_migrations_runner.rb +++ b/app/services/theme_settings_migrations_runner.rb @@ -13,7 +13,7 @@ class ThemeSettingsMigrationsRunner # @return [Integer|nil] The id of the category with the given name or nil if a category does not exist for the given # name. def get_category_id_by_name(category_name) - Category.where(name_lower: category_name).pick(:id) + Category.where("name_lower = LOWER(?)", category_name).pick(:id) end # @param [String] URL string to check if it is a valid absolute URL, path or anchor. diff --git a/spec/services/theme_settings_migrations_runner_spec.rb b/spec/services/theme_settings_migrations_runner_spec.rb index 549ec945a1f..7053650c548 100644 --- a/spec/services/theme_settings_migrations_runner_spec.rb +++ b/spec/services/theme_settings_migrations_runner_spec.rb @@ -356,14 +356,14 @@ describe ThemeSettingsMigrationsRunner do end it "attaches the getCategoryIdByName() function to the context of the migrations" do - category = Fabricate(:category, name: "some-category") + category = Fabricate(:category, name: "Some Category Name") theme.update_setting(:integer_setting, -10) theme.save! migration_field.update!(value: <<~JS) export default function migrate(settings, helpers) { - const categoryId = helpers.getCategoryIdByName("some-category"); + const categoryId = helpers.getCategoryIdByName("some CatEgory Name"); settings.set("integer_setting", categoryId); return settings; }