Skip to content

Conversation

@bsbonus
Copy link
Contributor

@bsbonus bsbonus commented May 22, 2025

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
Copy link
Collaborator

cielf commented May 23, 2025

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

@cielf cielf requested a review from dorner May 23, 2025 15:33
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.

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
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
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
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
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?

Copy link
Contributor Author

@bsbonus bsbonus May 28, 2025

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
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
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.

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

@awwaiid
Copy link
Collaborator

awwaiid commented Sep 13, 2025

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

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.

4 participants