gpt4 book ai didi

factory-bot - 工厂女孩 : How to pass the attribute's value in factory to it's association

转载 作者:行者123 更新时间:2023-12-01 06:38:03 25 4
gpt4 key购买 nike

如何将 :subscriber factory 中的“email”属性值传递给它的关联:authentication

例如:

factory :subscriber, :class => Subscriber do                                                                                                   
sequence(:name) { |n| "test_user_#{n}" }
sequence(:email) { |n| "test_user_#{n}@example.com"}
association :authentication, factory: :authentication, email: email
end

factory :authentication do
sequence(:email) { |n| "test_user_#{n}@example.com"}
password 'pass'
end

给我错误
ArgumentError:
Trait not registered: email

最佳答案

我认为您需要使关联调用动态化,因为电子邮件变量可能会发生变化:

authentication {association :authentication, email: email}

关于factory-bot - 工厂女孩 : How to pass the attribute's value in factory to it's association,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13201483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com