mirror of
https://github.com/rommapp/romm.git
synced 2026-06-29 15:25:46 +00:00
Collapse the separate `sort_name` column into `name_sort_key`, which is now
the single user-settable sort field: always normalized and indexed for fast
ordering, derived from `name` by default, and overridable. A new
`name_sort_key_custom` boolean marks user/metadata overrides so they survive
renames and rescans.
- Drop the `roms.sort_name` column; repurpose migration 0085 to add
`name_sort_key_custom`.
- Derive the key via `@validates("name")` unless pinned custom; the edit
dialog, unmatch flow, and ES-DE gamelist <sortname> set custom keys.
- update_rom / scan_rom keep the columns in sync explicitly (bulk update and
construction bypass / reorder the validator).
- Frontend: edit field drives name_sort_key (empty when auto), api sends the
override only when custom, regenerated types updated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
2.0 KiB
Python
49 lines
2.0 KiB
Python
"""Unit tests for DBRomsHandler's derived-column bookkeeping.
|
|
|
|
Bulk `update()` bypasses the ORM `@validates` hooks, so `update_rom` keeps
|
|
the columns derived from `name` / `fs_name` in sync explicitly.
|
|
"""
|
|
|
|
from handler.database import db_rom_handler
|
|
from models.rom import Rom
|
|
|
|
|
|
class TestUpdateRomDerivedColumns:
|
|
def test_update_name_resyncs_name_sort_key(self, rom: Rom):
|
|
updated = db_rom_handler.update_rom(rom.id, {"name": "The New Name 2"})
|
|
|
|
assert updated.name == "The New Name 2"
|
|
assert updated.name_sort_key == "new name 000000000002"
|
|
|
|
def test_update_fs_name_resyncs_all_parts(self, rom: Rom):
|
|
updated = db_rom_handler.update_rom(rom.id, {"fs_name": "Sonic (Europe).md"})
|
|
|
|
assert updated.fs_name == "Sonic (Europe).md"
|
|
assert updated.fs_name_no_tags == "Sonic"
|
|
assert updated.fs_name_no_ext == "Sonic (Europe)"
|
|
# The extension is resynced too — the rename endpoint used to omit it.
|
|
assert updated.fs_extension == "md"
|
|
|
|
def test_update_unrelated_field_leaves_derived_columns(self, rom: Rom):
|
|
updated = db_rom_handler.update_rom(rom.id, {"summary": "just a summary"})
|
|
|
|
assert updated.summary == "just a summary"
|
|
assert updated.fs_name_no_tags == "test_rom"
|
|
assert updated.fs_extension == "zip"
|
|
assert updated.name_sort_key == "test_rom"
|
|
|
|
def test_explicit_name_sort_key_marks_custom(self, rom: Rom):
|
|
updated = db_rom_handler.update_rom(rom.id, {"name_sort_key": "zelda"})
|
|
|
|
assert updated.name_sort_key == "zelda"
|
|
assert updated.name_sort_key_custom is True
|
|
|
|
def test_update_name_keeps_custom_sort_key(self, rom: Rom):
|
|
db_rom_handler.update_rom(rom.id, {"name_sort_key": "pinned"})
|
|
updated = db_rom_handler.update_rom(rom.id, {"name": "The New Name 2"})
|
|
|
|
# A pinned custom key is never clobbered by a name change.
|
|
assert updated.name == "The New Name 2"
|
|
assert updated.name_sort_key == "pinned"
|
|
assert updated.name_sort_key_custom is True
|