Skip to content

Commit c193eee

Browse files
gabeparra01Gabe
andauthored
Resolves #4818 Fix print feature for product drive with no participant (#4831)
* Fixing print feature for product drive donations with no participant * Lint fixes * Added label for product drive * Updating product drive participant factory and adding geocodable mock * Refactoring specs to use explicit checks * Using hardcoded address from stubbed class in rails_helper.rb * Removing previous changes to factory for product_drive_participants --------- Co-authored-by: Gabe <[email protected]>
1 parent dc37ff3 commit c193eee

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

app/pdfs/donation_pdf.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ def initialize(donation)
2020
@address = nil
2121
@email = nil
2222
when Donation::SOURCES[:product_drive]
23-
@name = donation.product_drive_participant.business_name
24-
@address = donation.product_drive_participant.address
25-
@email = donation.product_drive_participant.email
23+
if donation.product_drive_participant
24+
@name = donation.product_drive_participant.business_name
25+
@address = donation.product_drive_participant.address
26+
@email = donation.product_drive_participant.email
27+
else
28+
@name = "Product Drive -- #{donation.product_drive.name}"
29+
end
2630
when Donation::SOURCES[:misc]
2731
@name = "Misc. Donation"
2832
@address = nil

spec/pdfs/donation_pdf_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
create(:donation, organization: organization, donation_site: donation_site, source: Donation::SOURCES[:donation_site],
66
comment: "A donation comment")
77
end
8+
let(:product_drive) { create(:product_drive, name: "Second Best Product Drive") }
9+
let(:product_drive_participant) {
10+
create(:product_drive_participant, business_name: "A Good Place to Collect Diapers", address: "1500 Remount Road, Front Royal, VA 22630", email: "[email protected]")
11+
}
12+
let(:product_drive_donation) do
13+
create(:donation, organization: organization, product_drive: product_drive, source: Donation::SOURCES[:product_drive],
14+
product_drive_participant: product_drive_participant, comment: "A product drive donation")
15+
end
16+
let(:product_drive_donation_without_participant) do
17+
create(:donation, organization: organization, product_drive: product_drive, source: Donation::SOURCES[:product_drive], comment: "A product drive donation without participant")
18+
end
819
let(:item1) { FactoryBot.create(:item, name: "Item 1", package_size: 50, value_in_cents: 100) }
920
let(:item2) { FactoryBot.create(:item, name: "Item 2", value_in_cents: 200) }
1021
let(:item3) { FactoryBot.create(:item, name: "Item 3", value_in_cents: 300) }
@@ -65,4 +76,22 @@
6576
expect(pdf_test.page(1).text).to include("Total Items Received")
6677
end
6778
end
79+
80+
context "product drive donation" do
81+
it "renders correctly" do
82+
pdf = described_class.new(organization, product_drive_donation)
83+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
84+
expect(pdf_test.page(1).text).to include("A Good Place to Collect Diapers")
85+
expect(pdf_test.page(1).text).to include("[email protected]")
86+
expect(pdf_test.page(1).text).to include("1500 Remount Road, Front Royal, VA 22630")
87+
expect(pdf_test.page(1).text).to include("A product drive donation")
88+
end
89+
90+
it "renders correctly without a product drive participant" do
91+
pdf = described_class.new(organization, product_drive_donation_without_participant)
92+
pdf_test = PDF::Reader.new(StringIO.new(pdf.compute_and_render))
93+
expect(pdf_test.page(1).text).to include("Product Drive -- Second Best Product Drive")
94+
expect(pdf_test.page(1).text).to include("A product drive donation")
95+
end
96+
end
6897
end

0 commit comments

Comments
 (0)