Skip to content

Commit

Permalink
Tweak Note.sort behaviour
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
garethrees committed May 1, 2024
1 parent 847b43a commit 5b063d7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
2 changes: 1 addition & 1 deletion spec/models/note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5b063d7

Please sign in to comment.