【发布时间】:2016-09-04 09:09:06
【问题描述】:
我有一个委托给关联对象(AR/Postgres)的属性,并在调用工厂时尝试覆盖它。
class Patient
delegate :email, to: :credential
has_one :credential, as: :owner, dependent: :destroy
end
class Credential
belongs_to :owner, polymorphic: true
end
FactoryGirl.define do
factory :patient do
first_name 'Jane'
last_name 'Patient'
dob Date.parse('2005-01-11')
gender 'Female'
zipcode '80202'
after(:build) do |user|
create(:credential, owner: user)
end
end
end
FactoryGirl.define do
factory :credential do
password '!Secret15'
password_confirmation { password }
agree_to_terms true
sequence :email do |n|
"user#{n}@bar.com"
end
end
end
还有电话:
create(:patient, email: 'new@email.com')
它根本不起作用,并且该属性正在按默认顺序设置。
搜索了他们的文档和 Google,但找不到答案。非常感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails ruby postgresql rspec factory-bot