diff --git a/spec/factories/requests.rb b/spec/factories/requests.rb index e8a28128d8..ec61b97c09 100644 --- a/spec/factories/requests.rb +++ b/spec/factories/requests.rb @@ -28,29 +28,46 @@ def random_request_items request_items { random_request_items } comments { "Urgent" } partner_user { ::User.partner_users.first || create(:partners_user) } - end - trait :started do - status { 'started' } - end + # 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"] + ) + end + end + end - trait :fulfilled do - status { 'fulfilled' } - end + trait :started do + status { 'started' } + end - trait :pending do - status { 'pending' } - end + trait :fulfilled do + status { 'fulfilled' } + end + + trait :pending do + status { 'pending' } + end - trait :with_varied_quantities do - request_items { - # get 10 unique item ids - keys = Item.active.pluck(:id).sample(10) + trait :with_varied_quantities do + request_items { + # get 10 unique item ids + keys = Item.active.pluck(:id).sample(10) - # This *could* pass in error -- if the plucking order happens to match the end order. + # This *could* pass in error -- if the plucking order happens to match the end order. - item_quantities = [50, 150, 75, 125, 200, 3, 15, 88, 46, 22] - keys.map.with_index { |k, i| { "item_id" => k, "quantity" => item_quantities[i]} } - } + item_quantities = [50, 150, 75, 125, 200, 3, 15, 88, 46, 22] + keys.map.with_index { |k, i| { "item_id" => k, "quantity" => item_quantities[i]} } + } + end end end