Skip to content

Bug-5152-update-purchase-export-with-inactive-unpurchased-items - #5201

Merged
awwaiid merged 7 commits into
rubyforgood:mainfrom
bsbonus:5165-update-purchase-export-with-inactive-items
Jul 19, 2026
Merged

awwaiid merged 7 commits into
rubyforgood:mainfrom
bsbonus:5165-update-purchase-export-with-inactive-items

Conversation

@bsbonus

@bsbonus bsbonus commented May 22, 2025 •

Copy link
Copy Markdown
Contributor

Checklist:

X I have performed a self-review of my own code,
X I have commented my code, particularly in hard-to-understand areas,
X I have made corresponding changes to the documentation,
X I have added tests that prove my fix is effective or that my feature works,
X New and existing unit tests pass locally with my changes ("bundle exec rake"),
X Title include "WIP" if work is in progress.
X I acknowledge that I will not force push my branch once reviews have started.

Partial #5152 - partially, see main thread on this issue

Description

Updates the Purchases export to include inactive, unpurchased items in the export headers for consistency with the Distributions export

Type of change

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

How Has This Been Tested?

  1. Export the Distributions export as reference
  2. Ensure you have items that are inactive (with a unique name) and unpurchased
  3. Export the Purchases export and observe the number of columns for items don't match the Distribution export
  4. Export the Purchases export after the fix, observe the item columns now are consistent

See attached CSVs as reference
Distributions_as_reference.csv

Purchases export before fix:
purchases_before_fix.csv

Purchases after fix:
purchases after_fix.csv

@bsbonus bsbonus changed the title Bug-5165-update-purchase-export-with-inactive-unpurchased-items Bug-5152-update-purchase-export-with-inactive-unpurchased-items May 22, 2025
@cielf

cielf commented May 23, 2025

Copy link
Copy Markdown
Collaborator

Passes functional check. Over to @dorner for technical review.

@cielf
cielf requested a review from dorner May 23, 2025 15:33

@dorner dorner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks so much for all your help - had a few questions which are repeats of other PRs. :)

# needed rather than depending on external code to do it for me.
# This makes this code more self contained and efficient!
@purchases = Purchase.includes(
@organization = organization

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this need to be an instance variable?

private

attr_reader :purchases
attr_reader :purchases, :item_headers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this read from outside the class?

let(:unused_item) { create(:item, name: "Unused Item", organization: organization) }
let(:generated_csv_data) do
# Force unused_item to be created first
unused_item

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we replace line 121 with let! to avoid having to do this?

let(:generated_csv) { described_class.new(purchase_ids: purchase_ids, organization: organization).generate_csv }

it "returns a valid CSV string" do
expect(generated_csv).to be_a(String)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we do a test against "real" CSV data instead of just testing bits of it?

@bsbonus bsbonus May 28, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Totally can if you want -- it's kinda unnecessary imo.

Most of the test contentions are against generated_csv_data which is what builds the "real" csv data, and this block is testing the generate_csv method -- which is a very thin wrapper around CSV.generate. So writing tests against that method are kinda just testing CSV.generate?

I rearranged the file a bit so you can see this more clearly, with a #generate_csv_data and a #generate_csv context blocks. If you still want that in, let me know :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it's really kind of turning a set of unit tests into an integration test. Each individual part might be tested, but until we see a full CSV that we're comparing, with as few dynamic values as possible, we can't really know that we're doing it right. So we create data with specific values, generate the CSV, and compare against our result. Our comparison CSV shouldn't have anything dynamic except auto-generated IDs.

@bsbonus
bsbonus requested a review from dorner May 28, 2025 20:18
dorner
dorner previously requested changes May 30, 2025

@dorner dorner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I have to write something here even though I already made a comment thank you GitHub

@awwaiid

awwaiid commented Sep 13, 2025

Copy link
Copy Markdown
Collaborator

For this, it looks like we should switch to a CSV fixture based spec, and then it should be ready to merge.

@janeewheatley

Copy link
Copy Markdown
Collaborator

@bsbonus Hi! It looks like we have one outstanding comment here: #5201 (comment). Would you be able to take a look? Thanks!

awwaiid and others added 2 commits July 19, 2026 11:45
Per review: compare the full generated CSV against fixture files in
spec/fixtures/files/ instead of order-independent header/index lookups,
so any change to column order or content fails loudly.

- Pin vendor names, dates, amounts, and item names (previously Faker-
  random) so the fixtures can be fully static
- Rewrite the inactive-item and unused-item tests (bug rubyforgood#5152 coverage)
  as full-CSV fixture comparisons
- Convert the case-insensitive column sort test to a fixture comparison
  and drop the loose generate_csv wrapper tests, which the fixture
  assertions cover exactly

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BNy2e1J81K8xbvXraCeN8e
@awwaiid
awwaiid merged commit 86a7bae into rubyforgood:main Jul 19, 2026
11 checks passed
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

@bsbonus: Your PR Bug-5152-update-purchase-export-with-inactive-unpurchased-items is part of today's Human Essentials production release: 2026.08.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.

5 participants