Skip to content

Commit 3f48d10

Browse files
committed
#4770: Don't crash on deleted item for event history
1 parent 8da1718 commit 3f48d10

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

app/views/events/_snapshot_event_row.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<%= link_to storage_locs.find { |i| i.id == loc.id}.name, storage_location_path(loc.id) %>
1212
<td>
1313
<% loc.items.values.each do |entry| %>
14-
<%= link_to items.find { |i| i.id == entry.item_id}.name, item_path(entry.item_id) %>:
14+
<%= link_to items.find { |i| i.id == entry.item_id}&.name || "Item #{entry.item_id} (deleted)", item_path(entry.item_id) %>:
1515
<%= entry.quantity %><br>
1616
<% end %>
1717
</td>

spec/requests/events_requests_spec.rb

+38
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,44 @@
4747
expect(response.body).not_to include("99<br>")
4848
end
4949

50+
it "should show deleted items without crashing" do
51+
deleted_item = create(:item, organization: organization)
52+
travel(-1.day) do
53+
SnapshotEvent.create!(
54+
eventable: organization,
55+
organization_id: organization.id,
56+
event_time: Time.zone.now,
57+
data: EventTypes::Inventory.new(
58+
organization_id: organization.id,
59+
storage_locations: {
60+
storage_location.id => EventTypes::EventStorageLocation.new(
61+
id: storage_location.id,
62+
items: {
63+
item.id => EventTypes::EventItem.new(item_id: item.id, quantity: 0),
64+
item2.id => EventTypes::EventItem.new(item_id: item2.id, quantity: 0),
65+
deleted_item.id => EventTypes::EventItem.new(item_id: deleted_item.id, quantity: 0)
66+
}
67+
),
68+
storage_location2.id => EventTypes::EventStorageLocation.new(
69+
id: storage_location2.id,
70+
items: {
71+
item.id => EventTypes::EventItem.new(item_id: item.id, quantity: 0),
72+
item2.id => EventTypes::EventItem.new(item_id: item2.id, quantity: 0),
73+
deleted_item.id => EventTypes::EventItem.new(item_id: deleted_item.id, quantity: 0)
74+
}
75+
)
76+
}
77+
)
78+
)
79+
end
80+
deleted_id = deleted_item.id
81+
deleted_item.destroy
82+
subject
83+
expect(response.body).to include("Item1</a>")
84+
expect(response.body).to include("Item2</a>")
85+
expect(response.body).to include("Item #{deleted_id} (deleted)")
86+
end
87+
5088
context "with type filter" do
5189
let(:params) { {format: "html", filters: {by_type: "DonationEvent"}} }
5290

0 commit comments

Comments
 (0)