me.stub!(:code!)

May 06 2009

factory_girl callbacks

Eh, I don’t know if this is necessary, but I added callbacks to factory girl (http://github.com/agibralter/factory_girl/tree/master).

Factory.define :user_with_verified_email do |f|
  f.email                   { Factory.next(:email) }
  f.login                   { Factory.next(:name) }
  f.terms_and_conditions    1
  f.password                'password'
  
  f.add_callback(:after_save) do |user|
    user.verify_email!
  end
  f.add_callback(:before_save) do |user|
    # I don't really know what you would want to do here...
    # The dynamic attributes seem to handle most cases for
    # a before_save callback
  end
end

The callbacks only get called during Factory.create, not build, etc.

Comments (View)
blog comments powered by Disqus
Page 1 of 1