Files
sure/test/controllers
Erkan Doğan 71106f63b0 fix(merchants): preserve user-selected merchant colors on save (#2760) (#2802)
* fix(merchants): preserve user-selected merchant colors on save (#2760)

Fixes #2760.

## Problem

FamilyMerchant#set_default_color callback ran on before_validation and unconditionally executed self.color = COLORS.sample.

As a result:
- Any user-selected color or color passed via API/import was discarded and replaced with a random palette color.
- Renaming or updating any merchant field re-assigned a new random color on every save.

## Fix

Guard set_default_color so it only assigns a random palette color when color is blank (self.color = COLORS.sample if color.blank?).

## Test

- Added test/models/family_merchant_test.rb testing color preservation on creation and update, as well as default color fallback when blank.
- Updated test/controllers/family_merchants_controller_test.rb to assert persisted color on create and update.
- Verified in dev container: 9 runs, 22 assertions, 0 failures, 0 errors.
- RuboCop: 0 offenses.

* fix(merchants): validate hex format and fallback to default color if invalid

Add hex format validation (/\A#[0-9A-Fa-f]{6}\z/) to FamilyMerchant#color (matching Category and Tag models) and ensure set_default_color replaces invalid hex values (e.g. from API/CSV imports) with a default palette color before saving.

Responds to Codex review feedback on PR #2802.

---------

Co-authored-by: erkdgn <erkdgn@users.noreply.github.com>
2026-07-26 01:38:31 +02:00
..
2024-10-08 14:37:47 -05:00