Extra arguments for Factory Girl

Posted by J. Pablo Fernández on Stack Overflow See other posts from Stack Overflow or by J. Pablo Fernández
Published on 2010-04-19T09:56:21Z Indexed on 2010/04/20 10:03 UTC
Read the original article Hit count: 492

Filed under:
|
|

I need to pass extra arguments to factory girl to be used in a callback. Something like this (but more complex really):

Factory.define :blog do |blog|
  blog.name "Blah"

  blog.after_create do |blog|
    blog.posts += sample_posts
    blog.save!
  end
end

and then create it with something like this:

Factory.create(:blog, :sample_posts => [post1, post2])

Any ideas how to do it?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails