Getting your test records made for you

For the longest time I’ve been working with fixtures in ruby for testing, until
I recently discovered the factory_girl_rails gem. Fixtures are nice, they
provide a constant set of data to rely on without having to write them all the
time. While for a lot of purposes fixtures are nice, if you need to create new
objects all the time it can be a chore to to so. Especially maintaining them can
become quite a lot of work, especially when having objects which are
interrelated. This is where factories come in. They provide a new object
whenever you need one. I myself am still pretty new to it but it is just so easy
to even model interrelated objects and using them for your tests without having
to worry about updating them, unless your data model changes, which should not
happen that often. So just as a quick introduction those a 2 models following a
:belongs_to, :has_many relationship.

http://gist.github.com/646058.js

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s