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>
28 lines
836 B
Ruby
28 lines
836 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'captain_unit factory' do # rubocop:disable RSpec/DescribeClass
|
|
it 'cria uma unit com conta e brand próprios' do
|
|
unit = create(:captain_unit)
|
|
expect(unit).to be_persisted
|
|
expect(unit.account).to be_present
|
|
expect(unit.brand).to be_present
|
|
expect(unit.brand.account_id).to eq(unit.account_id)
|
|
end
|
|
|
|
it 'usa a conta fornecida' do
|
|
account = create(:account)
|
|
unit = create(:captain_unit, account: account)
|
|
expect(unit.account).to eq(account)
|
|
expect(unit.brand.account_id).to eq(account.id)
|
|
end
|
|
|
|
it 'reusa um brand existente da mesma conta' do
|
|
account = create(:account)
|
|
brand = create(:captain_brand, account: account)
|
|
unit = create(:captain_unit, account: account)
|
|
expect(unit.brand).to eq(brand)
|
|
end
|
|
end
|