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>
13 lines
375 B
Ruby
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
|