Skip to content

Conversation

@janeewheatley
Copy link
Collaborator

@janeewheatley janeewheatley commented Oct 20, 2025

Resolves #5428

Description

We fixed the list of purchases in the vendor view to be in reverse chronological order by entered date (which is the issued_at date instead of the created_at) of purchased goods. The issued_at date is the date when the goods were actually purchased on the store receipt (which is entered manually by a user) vs. just when the event was created (possibly weeks later).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I tested this code locally and saw that the purchase dates are now being ordered correctly. I have also created an automated test that appears to be passing.

Screenshots

Before:
image

After:
image

@janeewheatley janeewheatley force-pushed the fix-vendor-purchase-sorting-5428 branch from c7bef63 to 723519a Compare October 23, 2025 18:42
@janeewheatley janeewheatley requested a review from awwaiid October 23, 2025 18:43
</thead>
<tbody>
<% @vendor.purchases.each do |purchase| %>
<% @vendor.purchases.order(issued_at: :desc).each do |purchase| %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not doing anything but a very straight association call in the view - I'd rather add @purchases to the controller code and reference it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I removed the logic from the view and added to the vendors controller.


get vendor_path(vendor)

expect(vendor.reload.purchases.order(issued_at: :desc).to_a).to eq([new_purchase, middle_purchase, old_purchase])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually testing the view - you're just testing the database here. You need to inspect the response (i.e. response.body) to see that it contains the purchase dates in the expected order.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Adjusted the test, please check it out and let me know if it's better. Thanks!

@janeewheatley janeewheatley requested a review from dorner October 24, 2025 20:52
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Over to @awwaiid for functional test.

@dorner dorner dismissed awwaiid’s stale review October 26, 2025 14:34

We did tested this live.

@ruestitch ruestitch merged commit 1314d7a into rubyforgood:main Oct 26, 2025
12 of 13 checks passed
@ruestitch
Copy link
Collaborator

Functionally tested ALSO

@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2025

@janeewheatley: Your PR 5428 Sort vendor purchases by issued_at in reverse chronological order is part of today's Human Essentials production release: 2025.11.02.
Thank you very much for your contribution!

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.

list of purchases on vendor should be in reverse choronological order (by issued_at)

4 participants