Skip to content

Commit

Permalink
Merge pull request rubyforgood#4830 from coalest/fix-db-seed-transfer…
Browse files Browse the repository at this point in the history
…-flakiness

Fix transfer InventoryError during db seed
  • Loading branch information
cielf authored Dec 5, 2024
2 parents 8180529 + e1a540b commit d60dfae
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,14 +861,18 @@ def seed_quantity(item_name, organization, storage_location, quantity)
# ----------------------------------------------------------------------------
# Transfers
# ----------------------------------------------------------------------------
from_id, to_id = pdx_org.storage_locations.active_locations.limit(2).pluck(:id)
quantity = 5
inventory = View::Inventory.new(pdx_org.id)
# Ensure storage location has enough of item for transfer to succeed
item = inventory.items_for_location(from_id).find { _1.quantity > quantity }.db_item

transfer = Transfer.new(
comment: Faker::Lorem.sentence,
organization_id: pdx_org.id,
from_id: pdx_org.id,
to_id: sf_org.id,
line_items: [
LineItem.new(quantity: 5, item: pdx_org.items.first)
]
from_id: from_id,
to_id: to_id,
line_items: [ LineItem.new(quantity: quantity, item: item) ]
)
TransferCreateService.call(transfer)

Expand Down

0 comments on commit d60dfae

Please sign in to comment.