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
10 changes: 7 additions & 3 deletions app/pdfs/donation_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ def initialize(donation)
@address = nil
@email = nil
when Donation::SOURCES[:product_drive]
@name = donation.product_drive_participant.business_name
@address = donation.product_drive_participant.address
@email = donation.product_drive_participant.email
if donation.product_drive_participant
@name = donation.product_drive_participant.business_name
@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.

end
when Donation::SOURCES[:misc]
@name = "Misc. Donation"
@address = nil
Expand Down
28 changes: 28 additions & 0 deletions spec/pdfs/donation_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
create(:donation, organization: organization, donation_site: donation_site, source: Donation::SOURCES[:donation_site],
comment: "A donation comment")
end
let(:product_drive) { create(:product_drive, name: "Second Best Product Drive") }
let(:product_drive_participant) {
create(:product_drive_participant, business_name: "A Good Place to Collect Diapers", email: "[email protected]")
}
let(:product_drive_donation) do
create(:donation, organization: organization, product_drive: product_drive, source: Donation::SOURCES[:product_drive],
product_drive_participant: product_drive_participant, comment: "A product drive donation")
end
let(:product_drive_donation_without_participant) do
create(:donation, organization: organization, product_drive: product_drive, source: Donation::SOURCES[:product_drive], comment: "A product drive donation without participant")
end
let(:item1) { FactoryBot.create(:item, name: "Item 1", package_size: 50, value_in_cents: 100) }
let(:item2) { FactoryBot.create(:item, name: "Item 2", value_in_cents: 200) }
let(:item3) { FactoryBot.create(:item, name: "Item 3", value_in_cents: 300) }
Expand Down Expand Up @@ -65,4 +76,21 @@
expect(pdf_test.page(1).text).to include("Total Items Received")
end
end

context "product drive donation" do
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.

expect(pdf_test.page(1).text).to include(product_drive_donation.product_drive_participant.email)
expect(pdf_test.page(1).text).to include(product_drive_donation.comment)
end

it "renders correctly without a product drive participant" do
pdf = described_class.new(organization, product_drive_donation_without_participant)
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
expect(pdf_test.page(1).text).to include(product_drive_donation_without_participant.product_drive.name)
expect(pdf_test.page(1).text).to include(product_drive_donation_without_participant.comment)
end
end
end