Skip to content

Commit b984d0f

Browse files
authored
Merge branch 'main' into 5021-FIX-NEW-BARCODE-LIST-ON-VALIDATE
2 parents 17027d7 + cf3e528 commit b984d0f

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

app/views/events/_event_row.html.erb

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
</td>
3030
<td>
3131
<% event.data.items.each do |entry| %>
32-
<%= link_to items.find { |i| i.id == entry.item_id}.name, item_path(entry.item_id) %>:
32+
<% item = items.find { |i| i.id == entry.item_id} %>
33+
<% if item %>
34+
<%= link_to items.find { |i| i.id == entry.item_id}.name, item_path(entry.item_id) %>:
35+
<% else %>
36+
Item <%= entry.item_id %> (deleted)
37+
<% end %>
3338
<%= entry.from_storage_location == from_loc ? entry.quantity : -entry.quantity %><br>
3439
<% end %>
3540
</td>

app/views/events/_snapshot_event_row.html.erb

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
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+
<% item = items.find { |i| i.id == entry.item_id} %>
15+
<% if item %>
16+
<%= link_to items.find { |i| i.id == entry.item_id}.name, item_path(entry.item_id) %>:
17+
<% else %>
18+
Item <%= entry.item_id %> (deleted)
19+
<% end %>
1520
<%= entry.quantity %><br>
1621
<% end %>
1722
</td>

spec/requests/events_requests_spec.rb

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

50+
it "should show deleted items on regular event 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+
}
66+
),
67+
storage_location2.id => EventTypes::EventStorageLocation.new(
68+
id: storage_location2.id,
69+
items: {
70+
item.id => EventTypes::EventItem.new(item_id: item.id, quantity: 0),
71+
item2.id => EventTypes::EventItem.new(item_id: item2.id, quantity: 0)
72+
}
73+
)
74+
}
75+
)
76+
)
77+
donation = create(:donation, organization: organization)
78+
DonationEvent.create!(
79+
eventable: donation,
80+
organization_id: organization.id,
81+
event_time: Time.zone.now,
82+
data: EventTypes::InventoryPayload.new(
83+
items: [
84+
EventTypes::EventLineItem.new(item_id: item.id,
85+
quantity: 0,
86+
item_value_in_cents: 5,
87+
from_storage_location: nil,
88+
to_storage_location: storage_location.id),
89+
EventTypes::EventLineItem.new(item_id: item2.id,
90+
quantity: 0,
91+
item_value_in_cents: 5,
92+
from_storage_location: nil,
93+
to_storage_location: storage_location.id),
94+
EventTypes::EventLineItem.new(item_id: deleted_item.id,
95+
quantity: 0,
96+
item_value_in_cents: 5,
97+
from_storage_location: nil,
98+
to_storage_location: storage_location.id)
99+
]
100+
)
101+
)
102+
end
103+
deleted_id = deleted_item.id
104+
deleted_item.destroy
105+
subject
106+
expect(response.body).to include("Item1</a>")
107+
expect(response.body).to include("Item2</a>")
108+
expect(response.body).to include("Item #{deleted_id} (deleted)")
109+
end
110+
111+
it "should show deleted items on snapshot without crashing" do
112+
deleted_item = create(:item, organization: organization)
113+
travel(-1.day) do
114+
SnapshotEvent.create!(
115+
eventable: organization,
116+
organization_id: organization.id,
117+
event_time: Time.zone.now,
118+
data: EventTypes::Inventory.new(
119+
organization_id: organization.id,
120+
storage_locations: {
121+
storage_location.id => EventTypes::EventStorageLocation.new(
122+
id: storage_location.id,
123+
items: {
124+
item.id => EventTypes::EventItem.new(item_id: item.id, quantity: 0),
125+
item2.id => EventTypes::EventItem.new(item_id: item2.id, quantity: 0),
126+
deleted_item.id => EventTypes::EventItem.new(item_id: deleted_item.id, quantity: 0)
127+
}
128+
),
129+
storage_location2.id => EventTypes::EventStorageLocation.new(
130+
id: storage_location2.id,
131+
items: {
132+
item.id => EventTypes::EventItem.new(item_id: item.id, quantity: 0),
133+
item2.id => EventTypes::EventItem.new(item_id: item2.id, quantity: 0),
134+
deleted_item.id => EventTypes::EventItem.new(item_id: deleted_item.id, quantity: 0)
135+
}
136+
)
137+
}
138+
)
139+
)
140+
end
141+
deleted_id = deleted_item.id
142+
deleted_item.destroy
143+
subject
144+
expect(response.body).to include("Item1</a>")
145+
expect(response.body).to include("Item2</a>")
146+
expect(response.body).to include("Item #{deleted_id} (deleted)")
147+
end
148+
50149
context "with type filter" do
51150
let(:params) { {format: "html", filters: {by_type: "DonationEvent"}} }
52151

0 commit comments

Comments
 (0)