Skip to content

Commit 6d6eab2

Browse files
costajohntclaude
andcommitted
Sort donations item category filter alphabetically
QA found the item category filter options were not in alphabetical order. The item_categories collection was the only filter built without ordering, while the adjacent items and product_drives collections use the alphabetized scope. Add the standard alphabetized scope to ItemCategory (matching the pattern in 11 other models) and apply it here. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent d041063 commit 6d6eab2

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

app/models/item_category.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ItemCategory < ApplicationRecord
1818
has_many :items, -> { order(name: :asc) }, inverse_of: :item_category, dependent: :nullify
1919
has_and_belongs_to_many :partner_groups, dependent: :nullify
2020

21+
scope :alphabetized, -> { order(:name) }
22+
2123
before_destroy :ensure_no_associated_partner_groups
2224

2325
private

app/models/view/donations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def from_params(params:, organization:, helpers:)
5151
donations: donations,
5252
filters: filters,
5353
items: organization.items.alphabetized.select(:id, :name),
54-
item_categories: organization.item_categories.pluck(:name).uniq,
54+
item_categories: organization.item_categories.alphabetized.pluck(:name).uniq,
5555
paginated_donations: paginated_donations,
5656
product_drives: organization.product_drives.alphabetized,
5757
product_drive_participants: organization.product_drive_participants.alphabetized,

spec/system/donation_system_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@
161161
expect(page).to have_css("table tbody tr", count: 1)
162162
end
163163

164+
it "lists item categories alphabetically in the filter" do
165+
names = ["Zebra supplies", "Apple goods", "Mango wares"]
166+
names.each { |name| create(:item_category, name: name, organization: organization) }
167+
visit subject
168+
rendered = find("select[name='filters[by_category]']").all("option").map(&:text)
169+
ours = rendered.select { |option| names.include?(option) }
170+
expect(ours).to eq(names.sort)
171+
end
172+
164173
it_behaves_like "Date Range Picker", Donation, "issued_at"
165174

166175
it "Filters by multiple attributes" do

0 commit comments

Comments
 (0)