diff --git a/app/pdfs/donation_pdf.rb b/app/pdfs/donation_pdf.rb index 773e1b9095..bbf2a19eb0 100644 --- a/app/pdfs/donation_pdf.rb +++ b/app/pdfs/donation_pdf.rb @@ -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 diff --git a/spec/pdfs/donation_pdf_spec.rb b/spec/pdfs/donation_pdf_spec.rb index 21a8ee2174..5ceac9d3eb 100644 --- a/spec/pdfs/donation_pdf_spec.rb +++ b/spec/pdfs/donation_pdf_spec.rb @@ -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: "good@place.is") + } + 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) } @@ -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("good@place.is") + 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