Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #4818 Fix print feature for product drive with no participant #4831

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

gabeparra01
Copy link

@gabeparra01 gabeparra01 commented Dec 6, 2024

Description

Resolves #4818

The description for the issue is here: #4818

The changes for fixing the nil error were straightforward and I followed the recommended solution in the issue description.

One obstacle that I faced was testing the address attribute for a product drive participant. It is listed as an attribute in the model class and it is referenced in donation_pdf.rb. But I couldn't find an example Rspec test where it is being tested. When I tried to create a product drive participant object with an address in an Rspec test, I received an unrecognized method/pattern error. Please let me know if I should open another issue to look into this further or if there is something I am missing in the database schema?

Type of change

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

How Has This Been Tested?

  • Added two scenarios to donation_pdf_spec.rb
  • Manually tested in local workspace. I have added the screenshots below

Screenshots

Product Drive with participant.pdf
Product Drive without a participant.pdf

@coalest
Copy link
Collaborator

coalest commented Dec 7, 2024

I see the address field for product drive participants locally:
image
I think the factory bot for :product_drive_participant is missing that attribute. You can add it to spec/factories/product_drive_participant.rb to fix the issue.

It's a small fix, so I think you could add it to this PR.

@address = donation.product_drive_participant.address
@email = donation.product_drive_participant.email
else
@name = donation.product_drive.name
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 you are missing this requirement in your fix:

If it's a product drive, but without a product drive participant, put "Product Drive -- [the name of the product drive]" there instead.

If you just call name on the product drive, that prefix "Product Drive" will be missing.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

@gabeparra01
Copy link
Author

Updating product drive participant factory and adding geocodable mock

I added the address attribute to the factory class but after that I was seeing this error: ArgumentError: unknown stub request 123 Front Street, Atlanta, Georgia, 54321

The error was being through by the Geocodable class which is included in the ProductDriveParticipant model class. It was not easy to track down and I think that might be why there are not any Rspec tests that have tested this specific attribute yet. I had to add a mock for Geocodable to resolve the error: Updating product drive participant factory and adding geocodable mock

Please take a look and let me know if this solution looks good to you!

@coalest
Copy link
Collaborator

coalest commented Dec 7, 2024

Sorry for the trouble, I also didn't know that addresses are tied to the geocoder gem. Looks like it takes a address and then fetches the latitude/longitude. But since that requires an HTTP request (I think?), it is stubbed in the test suite. Check out this section in our rails_helper.rb file where we stub those calls/requests.

Looks like if you use one of those three addresses, you shouldn't need that additional mocking line.

@cielf cielf self-requested a review December 8, 2024 13:04
@cielf
Copy link
Collaborator

cielf commented Dec 8, 2024

Hey @gabeparra01. Thanks for this!

Note for next time -- we use the syntax Resolves #4831 to indicate the issue that is resolved, or Partial #4831 if it's only a partial fix. Our automated workflow in gitbhub understands Resolves to be an indicator that when the PR is merged, it can close the issue.

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Functionality looks good to me! Over to @dorner for technical notes.

@gabeparra01
Copy link
Author

Hey @gabeparra01. Thanks for this!

Note for next time -- we use the syntax Resolves #4831 to indicate the issue that is resolved, or Partial #4831 if it's only a partial fix. Our automated workflow in gitbhub understands Resolves to be an indicator that when the PR is merged, it can close the issue.

Anytime! Ok I will keep that in mind for next time!

@@ -20,6 +31,7 @@
before(:each) do
create(:line_item, itemizable: donation, item: item1, quantity: 50)
create(:line_item, itemizable: donation, item: item2, quantity: 100)
allow_any_instance_of(ProductDriveParticipant).to receive(:geocode).and_return(true)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't need this - see @coalest 's comment.

Copy link
Author

Choose a reason for hiding this comment

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

Ok I removed the stub statement and replaced the address value: Using hardcoded address from stubbed class in rails_helper.rb

@dorner @coalest Ready for another review!

it "renders correctly" do
pdf = described_class.new(organization, product_drive_donation)
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
expect(pdf_test.page(1).text).to include(product_drive_donation.product_drive_participant.business_name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I much prefer explicit checks - since you've given the participant a specific business name, you should be checking against that string rather than going back to the model you created.

Copy link
Author

Choose a reason for hiding this comment

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

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.

[Bug] Printing donation with Product Drive but no Product Drive Participant gives unhandled exception
4 participants