【发布时间】:2021-03-30 19:32:39
【问题描述】:
class User < ActiveRecord::Base
belongs_to :account
end
class Account < ActiveRecord::Base
has_many :users
has_many :reminders
end
class Reminder < ActiveRecord::Base
belongs_to :account
belongs_to :user
end
factory :user do
account
end
factory :reminder do
account
user
end
如何修改:reminder 工厂,以便我可以传入一个帐户,该帐户将用于提醒和用户?
r = FactoryBot.create(:reminder, account: Account.last)
r.account.id == r.user.account.id
【问题讨论】:
标签: ruby factory-bot