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
2 changes: 1 addition & 1 deletion app/services/itemizable_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def call(itemizable:, params: {}, event_class: nil)
# TODO once event sourcing has been out for long enough, we can safely remove this
if Event.where(eventable: itemizable).none? || UpdateExistingEvent.where(eventable: itemizable).any?
UpdateExistingEvent.publish(itemizable, previous, original_storage_location)
elsif inventory_changes?(previous, params[:line_items_attributes])
elsif inventory_changes?(previous, params[:line_items_attributes]) || itemizable.storage_location_id != original_storage_location.id
event_class&.publish(itemizable)
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/services/itemizable_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@
expect(UpdateExistingEvent.count).to eq(1)
expect(View::Inventory.total_inventory(organization.id)).to eq(75) # 40 - 5 (item1) - 10 (item2) + 50 (item3)
end

it "should send an event when the storage location changes" do
DonationEvent.publish(itemizable)
expect(DonationEvent.count).to eq(1)

# attributes that keep quantities the same but change storage location
same_quantities_attributes = {
storage_location_id: new_storage_location.id,
line_items_attributes: {
"0" => {item_id: item1.id, quantity: 10},
"1" => {item_id: item2.id, quantity: 10}
}
}

described_class.call(itemizable: itemizable, params: same_quantities_attributes, event_class: DonationEvent)

expect(DonationEvent.count).to eq(2)
end
end
describe "with distributions" do
before(:each) do
Expand Down