From d111b5a57bc87f83d6af70e133b0e19730464edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 14 Sep 2026 16:36:35 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20settings=20attendance=20r?= =?UTF-8?q?eads=20as=20a=20sorted=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Child tables have no ord. GET/PATCH returned alpha order after the first save; defaults now match, tests pin that. --- src/domain/settings.rs | 36 +++++++++++++++++++++--------------- tests/integration.rs | 4 ++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/domain/settings.rs b/src/domain/settings.rs index b59785d..102cb40 100644 --- a/src/domain/settings.rs +++ b/src/domain/settings.rs @@ -11,7 +11,6 @@ //! without a backfill (backfills crash boots — `DEFAULT` never rescues //! existing rows, and `UPDATE` re-validates whole records). - use serde::{Deserialize, Serialize}; use sqlx::types::Json; @@ -249,7 +248,11 @@ impl Settings { }) .to_vec(), ), - attendance_statuses: DEFAULT_ATTENDANCE_STATUSES.map(String::from).to_vec(), + attendance_statuses: { + let mut statuses = DEFAULT_ATTENDANCE_STATUSES.map(String::from).to_vec(); + statuses.sort(); + statuses + }, grade_bands: Json(Vec::new()), max_file_bytes: None, chatbot_history_turns: None, @@ -461,19 +464,22 @@ impl Settings { /// one (including rows saved before the field existed). An explicitly /// stored empty list stays empty — that is "no meal program", not "unset". pub fn get_meal_slots(&self) -> Vec { - self.meal_slots.as_ref().map(|slots| slots.0.clone()).unwrap_or_else(|| { - DEFAULT_MEAL_SLOTS - .map(|name| MealSlotDef { - name: name.to_string(), - // No built-in serving time, and the backend will not guess - // one: a slot with no hour has no instant for the cutoff to - // count back from, so the school's `meal_cancel_cutoff_ - // minutes` binds none of these slots until it sets real - // hours (see `check_cutoff`). - serving_minute: None, - }) - .to_vec() - }) + self.meal_slots + .as_ref() + .map(|slots| slots.0.clone()) + .unwrap_or_else(|| { + DEFAULT_MEAL_SLOTS + .map(|name| MealSlotDef { + name: name.to_string(), + // No built-in serving time, and the backend will not guess + // one: a slot with no hour has no instant for the cutoff to + // count back from, so the school's `meal_cancel_cutoff_ + // minutes` binds none of these slots until it sets real + // hours (see `check_cutoff`). + serving_minute: None, + }) + .to_vec() + }) } /// The dietary tags a dish and a student's profile may carry; the built-in diff --git a/tests/integration.rs b/tests/integration.rs index 20e02aa..601df8b 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -11479,7 +11479,7 @@ async fn settings_serve_defaults_and_gate_edits_to_manager() { ); assert_eq!( res.body["attendance_statuses"], - json!(["present", "absent", "late", "excused"]) + json!(["absent", "excused", "late", "present"]) ); assert_eq!(res.body["grade_bands"], json!([])); @@ -11518,7 +11518,7 @@ async fn settings_serve_defaults_and_gate_edits_to_manager() { ); assert_eq!( res.body["attendance_statuses"], - json!(["present", "absent", "late", "excused"]) + json!(["absent", "excused", "late", "present"]) ); // Every reader sees the new policy at once.