Creating a fixture via ActiveRecord





5
Date Submitted Thu. Feb. 8th, 2007 1:09 PM
Revision 1 of 1
Helper jeremec
Tags "ruby on rails" | fixtures | rails | Ruby
Comments 0 comments
I'm in the process of writing test fixtures for our rails site. A lot of my tests require authentication, so I've had to port our permissions system into a fixture. Rather than type out all of the information for the fixture, I decided to create a nested loop that will take care of this for me.

There's probably a rake task for this, but I wasn't able to find it, so I came up with my own solution. You'll have to do a little cleanup when it's done, however some slight mods to this loop could even eliminate that.

SomeModel.find_all().each do |sm|
  puts sm.identifier + ":\n"
  sm.attributes.keys.each do |smk|
    puts "  " + smk + ": " + sm.attributes[smk].to_s + "\n"
  end
end
 

Jereme Claussen

Comments

There are currently no comments for this snippet.

Voting

Votes Down