From 5b063d791c1ef93cdb33a9fea08a51cd24a89734 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 1 May 2024 12:15:27 +0100 Subject: [PATCH] Tweak Note.sort behaviour The default mental model for notes is roughly analogous to the Bootstrap alert levels [1]: * Red: Error/Danger * Yellow: Warning * Green: Success * Blue: Information This commit tweaks the ordering such that notes are sorted as above. If there's some sort of "Danger" note, then we want to show it before more general "Information". This ordering won't _always_ be correct, but it'll be Good Enough for the majority of cases. This also fixes the associated test. The `match_array` expectation is order-agnostic [2]: expect([1, 2, 3]).to match_array([2, 3, 1]) # pass [1] https://getbootstrap.com/2.2.0/components.html#alerts [2] https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/contain-exactly/ --- app/models/note.rb | 4 ++-- spec/models/note_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index bdc97080eb..7145abf4df 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -24,10 +24,10 @@ class Note < ApplicationRecord cattr_accessor :default_style, default: 'original' cattr_accessor :style_labels, default: { - '🔵 Blue': 'blue', '🔴 Red': 'red', - '🟢 Green': 'green', '🟡 Yellow': 'yellow', + '🟢 Green': 'green', + '🔵 Blue': 'blue', 'Original': 'original' } diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 521b62bb0d..a6e0b2df1b 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -97,7 +97,7 @@ def plain_body end it 'sorts based on enum value index' do - is_expected.to match_array([original, blue_1, blue_2, red, green, yellow]) + is_expected.to eq([red, yellow, green, blue_1, blue_2, original]) end end