views:

77

answers:

4

I'd like to write a Rake task that will load some development data for my app so I can see what the design looks like in the browser with some data populated in there. I've tried hacking together something using ActiveRecord and the Faker gem, but I'm having a hard time keeping it simple and practical. It quickly turns unwieldy.

Problem is the relationships among classes is fairly complex.

Just to give an idea of what it's like, here's a simplified version of part of the layout...

assets
------
make
model
serial_number
asset_type_id

asset_types
-----------
general_type
specific_type

attribute_names
---------------
asset_id
name

attribute_values
----------------
value
asset_id
attribute_name_id

Also have users and roles and a bunch of others.

Any suggestions? Helpful gems I should know about?

One thing to add... It would be nice if the data made sense. E.g. if the asset type was "computer" the make was "Dell" etc. though that isn't strictly necessary.

A: 

Do you have to generate the test data from scratch? That will be difficult, if the data structures are complicated.

Can't you just take some DB dump, anonymize it as appropriate and load that as test data? That's what we do normally.

sleske
+2  A: 

Check out the Populator GEM. You can supply an array of values and it will randomly select one.

Simone Carletti
+5  A: 

Take a look at this screencast by railscasts.com: http://railscasts.com/episodes/126-populating-a-database.

+2  A: 

You may also want to take a look at Machinist and/or Faker (which Machinist uses but is a gem in its own right).

Mike Woodhouse
This is what I was going to say, use Machinist to make valid model instances with Fake data and then you can loop it to create as many of each as you want.
railsninja