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

Merged
merged 13 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "Product Drive -- #{donation.product_drive.name}"
end
when Donation::SOURCES[:misc]
@name = "Misc. Donation"
@address = nil
Expand Down
29 changes: 29 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", address: "1500 Remount Road, Front Royal, VA 22630", 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,22 @@
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("A Good Place to Collect Diapers")
expect(pdf_test.page(1).text).to include("[email protected]")
expect(pdf_test.page(1).text).to include("1500 Remount Road, Front Royal, VA 22630")
expect(pdf_test.page(1).text).to include("A product drive donation")
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 -- Second Best Product Drive")
expect(pdf_test.page(1).text).to include("A product drive donation")
end
end
end
Loading