Skip to content
Open
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
4 changes: 4 additions & 0 deletions app/models/donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def donation_site_view
donation_site.nil? ? "N/A" : donation_site.name
end

def drive_participant_view

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a helper, not in the model class.

product_drive_participant.nil? ? "N/A" : product_drive_participant.display_name
end

def storage_view
storage_location.nil? ? "N/A" : storage_location.name
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/product_drive_participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ def donation_source_view

"#{contact_name} (participant)"
end

def display_name
business_name.presence || contact_name
end
end
2 changes: 2 additions & 0 deletions app/views/donations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
<th>Date</th>
<th>Source</th>
<th>Donation Site</th>
<th>Drive Participant</th>
<th>Storage Location</th>
</tr>
</thead>
<tbody>
<td><%= @donation.created_at.to_fs(:distribution_date) %></td>
<td><%= @donation.source %></td>
<td><%= @donation.donation_site_view %></td>
<td><%= @donation.drive_participant_view %></td>
<td><%= @donation.storage_view %></td> </tbody>
</table>
</div>
Expand Down
28 changes: 28 additions & 0 deletions spec/requests/donations_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down