iachat/spec/factories/captain/unit.rb
Rodribm10 325f05c3eb fix(spec): captain_unit factory now auto-creates brand in matching account
Replaced broken `association :brand, factory: :captain_brand, account: account`
(FactoryBot cannot evaluate `account` lazily that way) with a transient block
that does `Captain::Brand.find_by(account_id: account.id) || association(...)`,
ensuring the brand always belongs to the same account as the unit.
Adds factory spec (6 examples) confirming standalone create, account override,
and brand reuse all work correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 09:36:52 -03:00

13 lines
375 B
Ruby

FactoryBot.define do
factory :captain_unit, class: 'Captain::Unit' do
association :account
sequence(:name) { |n| "Unidade #{n}" }
inter_pix_key { SecureRandom.uuid }
inter_account_number { Faker::Number.number(digits: 8) }
brand do
Captain::Brand.find_by(account_id: account.id) || association(:captain_brand, account: account)
end
end
end