FactoryGirlでhas_oneモデルをテストする
userモデルが has_one :phone だとして。
factory :phone do number 00011112222 end factory :user do // fields after(:build) do |user| user.phone ||= FactoryGirl.build(:phone, user: user) end end
参考
http://stackoverflow.com/questions/17034423/factorygirl-has-one-association-and-validation-failed