Problem with Factory_girl, association and after_initialize

前端 未结 3 1625
予麋鹿
予麋鹿 2021-02-07 02:12

I have a Family class so defined:

class Family < ActiveRecord::Base
  after_initialize :initialize_family
  belongs_to :user
  validates :user, 
       :prese         


        
3条回答
  •  花落未央
    2021-02-07 02:30

    I believe that it's because the association is lazy, thus in the "after_initialize" there's no user yet.

    http://rdoc.info/github/thoughtbot/factory_girl/v1.3.3/file/README.rdoc

    Perhaps you can directly call one factory from another, but I didn't try this, e.g.

    f.user Factory(:user)
    

提交回复
热议问题