If you ever work with Rails and TDD, you may hear Factory girl: a great data mock gem to replace fixture. But sometime when your modal have some association with other modals, and that model have other associations, try to write a factory with callback (after build/create) become so hard. But thanks to thoughtbot, factory girl have data association build-in. You can read this post.
|
|
If your can FactoryGirl.create :post, that will create a post and a author associate to that. So in your rspec test, it’s easy to use them
|
|
What’s more? I found out it work with mongoid embed documuntation too.
For example, a playlist embed a list of videos, you can set this association the same way as relational database.
|
|
And FactoryGirl.create(:video) will create a playlist embed with one videos, etc
|
|