Something similar to this is failing for me:
class User < ActiveRecord::Base
after_initialize :do_something
def do_something
some_other_column = test
end
end
attrs = {:test => true}
fg_user = FactoryGirl.buid(User, attrs)
ar_user = User.new(attrs)
fg.some_other_column.should eq ar_user.some_other_column
If I use binding.pry in the after_initialize block, attributes are set when doing the AR new, but not FG build.
FactoryGirl assigns attributes after initialization intentionally to avoid attr_accessible issues. You can change how it initializes your class using initialize_with.
Most helpful comment
FactoryGirl assigns attributes after initialization intentionally to avoid
attr_accessibleissues. You can change how it initializes your class usinginitialize_with.