|
182 | 182 | storage_location = create(:storage_location, :with_items, item: item, item_quantity: 0, organization: organization)
|
183 | 183 | extra_item_name = "Extra Item"
|
184 | 184 | extra_item = create(:item, organization: organization, name: extra_item_name)
|
| 185 | + item_to_delete_name = "Item To Delete" |
| 186 | + item_to_delete = create(:item, organization: organization, name: item_to_delete_name) |
185 | 187 | TestInventory.create_inventory(organization, { storage_location.id => { item.id => 0, extra_item.id => 1 } })
|
186 | 188 | original_quantity = 100
|
187 | 189 | original_source = Donation::SOURCES[:manufacturer]
|
188 | 190 | original_date = DateTime.new(2024)
|
189 |
| - donation = create(:manufacturer_donation, :with_items, item: item, item_quantity: original_quantity, issued_at: original_date, organization: organization, storage_location: storage_location, source: original_source) |
| 191 | + donation = create(:manufacturer_donation, issued_at: original_date, organization: organization, storage_location: storage_location, source: original_source) |
| 192 | + add_item_donation = donation.as_json.merge({ |
| 193 | + line_items_attributes: { |
| 194 | + "0": { item_id: item.id, quantity: original_quantity }, |
| 195 | + "1": { item_id: item_to_delete.id, quantity: 1 } |
| 196 | + } |
| 197 | + }) |
| 198 | + |
| 199 | + put donation_path(id: donation.id, donation: add_item_donation) |
| 200 | + |
190 | 201 | distribution = {
|
191 | 202 | storage_location_id: storage_location.id,
|
192 | 203 | partner_id: create(:partner).id,
|
|
211 | 222 | extra_quantity = 1
|
212 | 223 | edited_quantity = 1
|
213 | 224 |
|
| 225 | + # deleted item is removed from line_items_attributes entirely |
214 | 226 | edited_donation = {
|
215 | 227 | source: edited_source,
|
216 | 228 | product_drive_id: edited_source_drive.id,
|
|
247 | 259 | expect(response.body).to include("value=\"#{edited_quantity}\" name=\"donation[line_items_attributes][0][quantity]")
|
248 | 260 | expect(response.body).to include("<option selected=\"selected\" value=\"#{extra_item.id}\">#{extra_item_name}</option>")
|
249 | 261 | expect(response.body).to include("value=\"#{extra_quantity}\" name=\"donation[line_items_attributes][1][quantity]")
|
| 262 | + expect(response.body).not_to include("<option selected=\"selected\" value=\"#{item_to_delete.id}\">#{item_to_delete_name}</option>") |
250 | 263 | end
|
251 | 264 | end
|
252 | 265 | end
|
|
0 commit comments