Skip to content

Commit

Permalink
Only build item_requests in factory when requested
Browse files Browse the repository at this point in the history
There are unfortunately existing specs which don't pass in valid data
for building out the item_requests, so here we make it an explicit trait
that must be requested.

[#4399]
  • Loading branch information
awwaiid committed Jul 14, 2024
1 parent a62f374 commit 9e59dba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
24 changes: 13 additions & 11 deletions spec/factories/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ def random_request_items

# For compatibility we can take in a list of request_items and turn it into a
# list of item_requests
after(:build) do |request|
if request.item_requests.empty?
request.request_items.each do |request_item|
item = Item.find(request_item['item_id'])
request.item_requests << Partners::ItemRequest.new(
item_id: item.id,
quantity: request_item['quantity'],
name: item.name,
partner_key: item.partner_key,
request_unit: request_item["request_unit"]
)
trait :with_item_requests do
after(:build) do |request|
if request.item_requests.empty?
request.request_items.each do |request_item|
item = Item.find(request_item['item_id'])
request.item_requests << Partners::ItemRequest.new(
item_id: item.id,
quantity: request_item['quantity'],
name: item.name,
partner_key: item.partner_key,
request_unit: request_item["request_unit"]
)
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/requests/partners/requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
create(:item_unit, item: item3, name: "flat")
request = create(
:request,
:with_item_requests,
partner_id: partner.id,
partner_user_id: partner_user.id,
request_items: [
Expand Down

0 comments on commit 9e59dba

Please sign in to comment.