after(:crate)を使いましょう
case
userがteacher_accountにアップデートした際、
user_performanceを関連データとして作成。
user_performanceはポリモーフィック関連を利用
code
FactoryBot.define do
factory :user do
sequence(:username) { |n| "Testuser#{n}" }
sequence(:email) { |n| "tester#{n}@example.com" }
password { 'password' }
phone_number { "0#{rand(0..9)}0#{rand(1_000_000..99_999_999)}" }
confirmed_at { Date.today }
trait :teacher_account do
teacher { true }
after(:create) do |user|
create(:user_performance, performancable: user)
end
end
end
end