Skip to content

Conversation

@costajohnt
Copy link

@costajohnt costajohnt commented Feb 8, 2026

Summary

  • Adds by_item_id and by_item_category_id scopes to the Donation model, mirroring the existing scopes on Distribution
  • Wires up a "Filter by Item" dropdown on the donations index page using the existing filter_select helper
  • Permits the new filter params in both DonationsController#filter_params and View::Donations.filter_params
  • Adds model specs for both new scopes and a system spec for the item filter

Closes #5105

Approach

Followed the pattern established by the Distribution model's by_item_id scope (line 54 of distribution.rb) and the Distribution index page's item filter dropdown. The Filterable concern's class_filter method handles scope chaining automatically.

Files changed

File Change
app/models/donation.rb Add by_item_id and by_item_category_id scopes
app/models/view/donations.rb Add items to Data.define, permit new filter params, add selected_item accessor
app/controllers/donations_controller.rb Permit :by_item_id and :by_item_category_id in filter_params
app/views/donations/index.html.erb Add "Filter by Item" dropdown
spec/models/donation_spec.rb Scope specs for by_item_id and by_item_category_id
spec/system/donation_system_spec.rb System spec for item filtering on donations page

Test plan

  • Model spec: by_item_id returns only donations containing the specified item
  • Model spec: by_item_category_id returns only donations with items in the specified category
  • System spec: selecting an item from the filter dropdown and clicking Filter shows only matching donations
  • Existing filter tests continue to pass (category, source, manufacturer, etc.)
  • CSV export respects the item filter (handled automatically by class_filter)

Add by_item_id and by_item_category_id scopes to Donation model,
mirroring the existing Distribution filters. Wire up the item filter
dropdown on the donations index page and permit the new params in both
the controller and the View::Donations data object.

Closes rubyforgood#5105
@costajohnt costajohnt force-pushed the feat/donation-item-filter-5105 branch from 9395a77 to 3e2f4fe Compare February 8, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide filters by item and by categories on donations

1 participant