From 0551b16c434b8f23af78452355cfc867b5eab2ae Mon Sep 17 00:00:00 2001 From: Gabe Date: Fri, 6 Dec 2024 16:27:58 -0600 Subject: [PATCH 1/7] Fixing print feature for product drive donations with no participant --- app/pdfs/donation_pdf.rb | 10 +++++++--- spec/pdfs/donation_pdf_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/pdfs/donation_pdf.rb b/app/pdfs/donation_pdf.rb index 773e1b9095..bdd09f059d 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 = 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..6b94afcee0 100644 --- a/spec/pdfs/donation_pdf_spec.rb +++ b/spec/pdfs/donation_pdf_spec.rb @@ -5,6 +5,16 @@ 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: "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 +75,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) + 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 From 4b1f019b8d03ee336e806c5786bedbc38d589b97 Mon Sep 17 00:00:00 2001 From: Gabe Date: Fri, 6 Dec 2024 16:50:07 -0600 Subject: [PATCH 2/7] Lint fixes --- spec/pdfs/donation_pdf_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/pdfs/donation_pdf_spec.rb b/spec/pdfs/donation_pdf_spec.rb index 6b94afcee0..38348d0f1b 100644 --- a/spec/pdfs/donation_pdf_spec.rb +++ b/spec/pdfs/donation_pdf_spec.rb @@ -7,7 +7,8 @@ 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: "good@place.is") } + create(:product_drive_participant, business_name: "A Good Place to Collect Diapers", 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") From 0257ea917652c5f664ecd06e3b653d1916c739a4 Mon Sep 17 00:00:00 2001 From: Gabe Date: Sat, 7 Dec 2024 09:33:57 -0600 Subject: [PATCH 3/7] Added label for product drive --- app/pdfs/donation_pdf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pdfs/donation_pdf.rb b/app/pdfs/donation_pdf.rb index bdd09f059d..bbf2a19eb0 100644 --- a/app/pdfs/donation_pdf.rb +++ b/app/pdfs/donation_pdf.rb @@ -25,7 +25,7 @@ def initialize(donation) @address = donation.product_drive_participant.address @email = donation.product_drive_participant.email else - @name = donation.product_drive.name + @name = "Product Drive -- #{donation.product_drive.name}" end when Donation::SOURCES[:misc] @name = "Misc. Donation" From 572f94b8ef97e3dc1c08b075de62ebe0edfc5b36 Mon Sep 17 00:00:00 2001 From: Gabe Date: Sat, 7 Dec 2024 10:24:18 -0600 Subject: [PATCH 4/7] Updating product drive participant factory and adding geocodable mock --- spec/factories/product_drive_participants.rb | 1 + spec/pdfs/donation_pdf_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/factories/product_drive_participants.rb b/spec/factories/product_drive_participants.rb index 997f6b9a8a..bf3622a72f 100644 --- a/spec/factories/product_drive_participants.rb +++ b/spec/factories/product_drive_participants.rb @@ -21,6 +21,7 @@ organization { Organization.try(:first) || create(:organization) } contact_name { "Don Draper" } business_name { "Awesome Business" } + address { "123 Front Street, Atlanta, Georgia, 54321" } sequence(:email) { |n| "don#{n}@scdp.com" } phone { "212-555-1111" } comment { "A bit of a lush and philanderer." } diff --git a/spec/pdfs/donation_pdf_spec.rb b/spec/pdfs/donation_pdf_spec.rb index 38348d0f1b..68b2b84965 100644 --- a/spec/pdfs/donation_pdf_spec.rb +++ b/spec/pdfs/donation_pdf_spec.rb @@ -7,7 +7,7 @@ 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: "good@place.is") + create(:product_drive_participant, business_name: "A Good Place to Collect Diapers", address: "123 Front Street, Atlanta, Georgia, 54321", email: "good@place.is") } let(:product_drive_donation) do create(:donation, organization: organization, product_drive: product_drive, source: Donation::SOURCES[:product_drive], @@ -31,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) end specify "#donation_data" do @@ -83,6 +84,7 @@ 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) 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.product_drive_participant.address) expect(pdf_test.page(1).text).to include(product_drive_donation.comment) end From dd98442b16ea8edfdf706aa8d75bb14a6b397dde Mon Sep 17 00:00:00 2001 From: Gabe Date: Wed, 11 Dec 2024 09:05:37 -0600 Subject: [PATCH 5/7] Refactoring specs to use explicit checks --- spec/pdfs/donation_pdf_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/pdfs/donation_pdf_spec.rb b/spec/pdfs/donation_pdf_spec.rb index 68b2b84965..46f0dc6293 100644 --- a/spec/pdfs/donation_pdf_spec.rb +++ b/spec/pdfs/donation_pdf_spec.rb @@ -82,17 +82,17 @@ 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) - 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.product_drive_participant.address) - expect(pdf_test.page(1).text).to include(product_drive_donation.comment) + 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("123 Front Street, Atlanta, Georgia, 54321") + 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_donation_without_participant.product_drive.name) - expect(pdf_test.page(1).text).to include(product_drive_donation_without_participant.comment) + 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 From 0023558efa8f0f14e640e684fa976a607fa95bc9 Mon Sep 17 00:00:00 2001 From: Gabe Date: Wed, 11 Dec 2024 09:10:49 -0600 Subject: [PATCH 6/7] Using hardcoded address from stubbed class in rails_helper.rb --- spec/pdfs/donation_pdf_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/pdfs/donation_pdf_spec.rb b/spec/pdfs/donation_pdf_spec.rb index 46f0dc6293..5ceac9d3eb 100644 --- a/spec/pdfs/donation_pdf_spec.rb +++ b/spec/pdfs/donation_pdf_spec.rb @@ -7,7 +7,7 @@ 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: "123 Front Street, Atlanta, Georgia, 54321", email: "good@place.is") + 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], @@ -31,7 +31,6 @@ 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) end specify "#donation_data" do @@ -84,7 +83,7 @@ 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("123 Front Street, Atlanta, Georgia, 54321") + 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 From 0662162aef59345d5b703b52082f1695c9d58f53 Mon Sep 17 00:00:00 2001 From: Gabe Date: Fri, 13 Dec 2024 09:57:21 -0600 Subject: [PATCH 7/7] Removing previous changes to factory for product_drive_participants --- spec/factories/product_drive_participants.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/factories/product_drive_participants.rb b/spec/factories/product_drive_participants.rb index bf3622a72f..997f6b9a8a 100644 --- a/spec/factories/product_drive_participants.rb +++ b/spec/factories/product_drive_participants.rb @@ -21,7 +21,6 @@ organization { Organization.try(:first) || create(:organization) } contact_name { "Don Draper" } business_name { "Awesome Business" } - address { "123 Front Street, Atlanta, Georgia, 54321" } sequence(:email) { |n| "don#{n}@scdp.com" } phone { "212-555-1111" } comment { "A bit of a lush and philanderer." }