I have a Family class so defined:
class Family < ActiveRecord::Base
after_initialize :initialize_family
belongs_to :user
validates :user,
:prese
Since after_initialize
is triggered after new objects are instantiated and factory_girl builds instances by calling new
without any arguments by default, you must use initialize_with to overwrite the default build.
FactoryGirl.define do
factory :family do
initialize_with { new(user: build(:user)) }
end
end