I previously posted about my friendly_fixtures plugin
It’s now available at github: http://github.com/dfl/friendly_fixtures/tree/master
factories-and-workers at github
Factories and Workers is a Rails plugin originally written by Nathan Herald @ myobie.com after being inspired by Dan Manges’ blog post on factories. It uses some slick metaprogramming to generate factory methods for your ActiveRecord models. Over the past few months I’ve refactored the code, added a bunch of new features, and most importantly wrote some tests!
See it in action:
>> factory :monkey, { :name => "George" }
=> #<FactoryBuilder:0x1a4f2a8>
>> valid_monkey_attributes
=> {:name=>"George"}
>> build_monkey
=> #<Monkey id: nil, name: "George">
>> build_monkey( :name => "Bob" )
=> #<Monkey id: nil, name: "Bob">
>> Monkey.count
=> 0
>> create_monkey
=> #<Monkey id: 1, name: "George">
>> Monkey.count
=> 1
There’s much more info in the README.
In a previous post, I posted a monkey patch to enhance the behavior of fixtures. I converted it into a plugin format for convenience and testing purposes. I am still aiming to submit it as a patch to Rails 2.0. I’d appreciate any feedback!
get it here:
svn export --username=public svn://internautdesign.com/public/plugins/friendly_fixtures vendor/plugins/friendly_fixtures
UPDATE: now available at github: http://github.com/dfl/friendly_fixtures/tree/master
from the README:
FriendlyFixtures
This plugin is a simple extension to add some cool features to the fixtures macro in Test::Unit. It is intended for Rails 2.0, but works with 1.2.3 as well.
It enables you to:- load dependent models, which are found by object introspection on a model’s ActiveRecord associations.
- assert that all the loaded fixtures are valid. This can be very helpful in finding bugs.
Example Usage:
class SomeTest < Test::Unit::TestCase
fixtures :user, :dependencies => true, :validate => true
end
