Files
project-work/worker-toolkit-stocks-in-the-future/repo/test/factories/orders.rb
Eric Bell 392781f7aa chore: init commit
in worker.../repo/GITFOLDER.zip is the .git folder.
2026-08-11 14:44:09 -04:00

52 lines
990 B
Ruby

# frozen_string_literal: true
FactoryBot.define do
factory :order do
stock
shares { 1 }
user { create(:student) }
action { :sell } # Default to sell to avoid validation issues
end
trait :pending do
status { :pending }
end
trait :completed do
status { :completed }
end
trait :canceled do
status { :canceled }
end
trait :buy do
action { :buy }
end
trait :sell do
action { :sell }
end
trait :with_sufficient_funds do
after(:create) do |order|
order.user.portfolio.portfolio_transactions.create!(
amount_cents: 100_000, # $1000 - plenty for testing
transaction_type: :deposit
)
end
end
trait :with_sufficient_shares do
after(:create) do |order|
create(
:portfolio_stock,
portfolio: order.user.portfolio,
stock: order.stock,
shares: 100, # Plenty of shares for testing
purchase_price: order.stock.price_cents
)
end
end
end