Settings attendance reads as a sorted set
Browse files at this commitd111b5a57bc87f83d6af70e133b0e19730464edfParent: eaa4976- fix
- settings attendance reads as a sorted set
2 changed files +23 -17
- src/domain/settings.rs +21 -15
- tests/integration.rs +2 -2
src/domain/settings.rsmodified+21 -15
| @@ -11,7 +11,6 @@ | |||
| 11 | //! without a backfill (backfills crash boots — `DEFAULT` never rescues | 11 | //! without a backfill (backfills crash boots — `DEFAULT` never rescues |
| 12 | //! existing rows, and `UPDATE` re-validates whole records). | 12 | //! existing rows, and `UPDATE` re-validates whole records). |
| 13 | 13 | ||
| 14 | - | ||
| 15 | use serde::{Deserialize, Serialize}; | 14 | use serde::{Deserialize, Serialize}; |
| 16 | use sqlx::types::Json; | 15 | use sqlx::types::Json; |
| 17 | 16 | ||
| @@ -249,7 +248,11 @@ impl Settings { | |||
| 249 | }) | 248 | }) |
| 250 | .to_vec(), | 249 | .to_vec(), |
| 251 | ), | 250 | ), |
| 252 | - attendance_statuses: DEFAULT_ATTENDANCE_STATUSES.map(String::from).to_vec(), | 251 | + attendance_statuses: { |
| 252 | + let mut statuses = DEFAULT_ATTENDANCE_STATUSES.map(String::from).to_vec(); | ||
| 253 | + statuses.sort(); | ||
| 254 | + statuses | ||
| 255 | + }, | ||
| 253 | grade_bands: Json(Vec::new()), | 256 | grade_bands: Json(Vec::new()), |
| 254 | max_file_bytes: None, | 257 | max_file_bytes: None, |
| 255 | chatbot_history_turns: None, | 258 | chatbot_history_turns: None, |
| @@ -461,19 +464,22 @@ impl Settings { | |||
| 461 | /// one (including rows saved before the field existed). An explicitly | 464 | /// one (including rows saved before the field existed). An explicitly |
| 462 | /// stored empty list stays empty — that is "no meal program", not "unset". | 465 | /// stored empty list stays empty — that is "no meal program", not "unset". |
| 463 | pub fn get_meal_slots(&self) -> Vec<MealSlotDef> { | 466 | pub fn get_meal_slots(&self) -> Vec<MealSlotDef> { |
| 464 | - self.meal_slots.as_ref().map(|slots| slots.0.clone()).unwrap_or_else(|| { | 467 | + self.meal_slots |
| 465 | - DEFAULT_MEAL_SLOTS | 468 | + .as_ref() |
| 466 | - .map(|name| MealSlotDef { | 469 | + .map(|slots| slots.0.clone()) |
| 467 | - name: name.to_string(), | 470 | + .unwrap_or_else(|| { |
| 468 | - // No built-in serving time, and the backend will not guess | 471 | + DEFAULT_MEAL_SLOTS |
| 469 | - // one: a slot with no hour has no instant for the cutoff to | 472 | + .map(|name| MealSlotDef { |
| 470 | - // count back from, so the school's `meal_cancel_cutoff_ | 473 | + name: name.to_string(), |
| 471 | - // minutes` binds none of these slots until it sets real | 474 | + // No built-in serving time, and the backend will not guess |
| 472 | - // hours (see `check_cutoff`). | 475 | + // one: a slot with no hour has no instant for the cutoff to |
| 473 | - serving_minute: None, | 476 | + // count back from, so the school's `meal_cancel_cutoff_ |
| 474 | - }) | 477 | + // minutes` binds none of these slots until it sets real |
| 475 | - .to_vec() | 478 | + // hours (see `check_cutoff`). |
| 476 | - }) | 479 | + serving_minute: None, |
| 480 | + }) | ||
| 481 | + .to_vec() | ||
| 482 | + }) | ||
| 477 | } | 483 | } |
| 478 | 484 | ||
| 479 | /// The dietary tags a dish and a student's profile may carry; the built-in | 485 | /// The dietary tags a dish and a student's profile may carry; the built-in |
tests/integration.rsmodified+2 -2
| @@ -11479,7 +11479,7 @@ async fn settings_serve_defaults_and_gate_edits_to_manager() { | |||
| 11479 | ); | 11479 | ); |
| 11480 | assert_eq!( | 11480 | assert_eq!( |
| 11481 | res.body["attendance_statuses"], | 11481 | res.body["attendance_statuses"], |
| 11482 | - json!(["present", "absent", "late", "excused"]) | 11482 | + json!(["absent", "excused", "late", "present"]) |
| 11483 | ); | 11483 | ); |
| 11484 | assert_eq!(res.body["grade_bands"], json!([])); | 11484 | assert_eq!(res.body["grade_bands"], json!([])); |
| 11485 | 11485 | ||
| @@ -11518,7 +11518,7 @@ async fn settings_serve_defaults_and_gate_edits_to_manager() { | |||
| 11518 | ); | 11518 | ); |
| 11519 | assert_eq!( | 11519 | assert_eq!( |
| 11520 | res.body["attendance_statuses"], | 11520 | res.body["attendance_statuses"], |
| 11521 | - json!(["present", "absent", "late", "excused"]) | 11521 | + json!(["absent", "excused", "late", "present"]) |
| 11522 | ); | 11522 | ); |
| 11523 | 11523 | ||
| 11524 | // Every reader sees the new policy at once. | 11524 | // Every reader sees the new policy at once. |