2
私は、関連するオブジェクト(AR/Postgres)に属性を委譲しており、ファクトリを呼び出すときにそれを上書きしようとしています。factory_girlの委任属性を上書きする方法は?
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: '[email protected]')
それは単純に動作していない、と属性がデフォルトの順序で設定されてきています。
彼らのドキュメントとGoogleを磨き、答えを見つけることができませんでした。どんな助けでも大歓迎です。
恐ろしい:属性は、コールバックでは利用できないので、コールバックブロックの2番目の引数である評価者から
email
を得る:ここに文書化 – idknox