diff --git a/app/helpers/donations_helper.rb b/app/helpers/donations_helper.rb
index 4888b309cd..4ca6d5c7a6 100644
--- a/app/helpers/donations_helper.rb
+++ b/app/helpers/donations_helper.rb
@@ -21,6 +21,10 @@ def total_number_of_drives(range = selected_range)
current_organization.product_drives.within_date_range(formatted_range).count
end
+ def drive_participant_view(donation)
+ donation.product_drive_participant.nil? ? "N/A" : donation.product_drive_participant.display_name
+ end
+
def options_with_new(records)
model_class = records.klass
label = "---Create New #{model_class.model_name.human}---"
diff --git a/app/models/product_drive_participant.rb b/app/models/product_drive_participant.rb
index dc1ab6823e..f4029f4c58 100644
--- a/app/models/product_drive_participant.rb
+++ b/app/models/product_drive_participant.rb
@@ -49,4 +49,8 @@ def donation_source_view
"#{contact_name} (participant)"
end
+
+ def display_name
+ business_name.presence || contact_name
+ end
end
diff --git a/app/views/donations/show.html.erb b/app/views/donations/show.html.erb
index 948fdcb57c..b5f2ea0b3a 100644
--- a/app/views/donations/show.html.erb
+++ b/app/views/donations/show.html.erb
@@ -34,6 +34,7 @@
Date |
Source |
Donation Site |
+ Drive Participant |
Storage Location |
@@ -41,6 +42,7 @@
<%= @donation.created_at.to_fs(:distribution_date) %> |
<%= @donation.source %> |
<%= @donation.donation_site_view %> |
+ <%= drive_participant_view(@donation) %> |
<%= @donation.storage_view %> |
diff --git a/spec/requests/donations_requests_spec.rb b/spec/requests/donations_requests_spec.rb
index fe12b80fcf..a706c0e889 100644
--- a/spec/requests/donations_requests_spec.rb
+++ b/spec/requests/donations_requests_spec.rb
@@ -237,6 +237,34 @@
expect(pdf.text).to include("Print")
end
+ context "with a donation from a product drive participant" do
+ let(:participant) do
+ create(:product_drive_participant, business_name: "Acme Diaper Drive", organization: organization)
+ end
+ let!(:donation) do
+ create(:product_drive_donation, :with_items, item: item, product_drive_participant: participant, organization: organization)
+ end
+
+ it "shows the participant in the Drive Participant column" do
+ get donation_path(id: donation.id)
+ page = Nokogiri::HTML(response.body)
+ headers = page.at_css("table thead").css("th").map(&:text)
+ cells = page.at_css("table tbody").css("td").map(&:text)
+ expect(headers.index("Drive Participant")).to eq(headers.index("Donation Site") + 1)
+ expect(cells[headers.index("Drive Participant")]).to eq("Acme Diaper Drive")
+ end
+ end
+
+ context "with a donation that has no product drive participant" do
+ it "shows N/A in the Drive Participant column" do
+ get donation_path(id: donation.id)
+ page = Nokogiri::HTML(response.body)
+ headers = page.at_css("table thead").css("th").map(&:text)
+ cells = page.at_css("table tbody").css("td").map(&:text)
+ expect(cells[headers.index("Drive Participant")]).to eq("N/A")
+ end
+ end
+
it "shows an enabled edit button" do
get donation_path(id: donation.id)
page = Nokogiri::HTML(response.body)