FIX: Make `getCategoryIdByName` theme migration helper case insensitive (#26878)

This commit is contained in:
Alan Guo Xiang Tan 2024-05-06 12:42:58 +08:00 committed by GitHub
parent e607dd3767
commit b6f6852bba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -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 # @return [Integer|nil] The id of the category with the given name or nil if a category does not exist for the given
# name. # name.
def get_category_id_by_name(category_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 end
# @param [String] URL string to check if it is a valid absolute URL, path or anchor. # @param [String] URL string to check if it is a valid absolute URL, path or anchor.

View File

@ -356,14 +356,14 @@ describe ThemeSettingsMigrationsRunner do
end end
it "attaches the getCategoryIdByName() function to the context of the migrations" do 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.update_setting(:integer_setting, -10)
theme.save! theme.save!
migration_field.update!(value: <<~JS) migration_field.update!(value: <<~JS)
export default function migrate(settings, helpers) { export default function migrate(settings, helpers) {
const categoryId = helpers.getCategoryIdByName("some-category"); const categoryId = helpers.getCategoryIdByName("some CatEgory Name");
settings.set("integer_setting", categoryId); settings.set("integer_setting", categoryId);
return settings; return settings;
} }