Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ModelFactory is a Rails plugin that provides an easy way to create models for testing purposes.
Ruby JavaScript
Tree: 0adefbf3fe

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
LICENSE
README
init.rb
model_factory-1.0.0.gem
model_factory.gemspec

README

= ModelFactory

by Matthias Hennemeyer <mhennemeyer@gmail.com>

== Introduction

Create objects with ease:

  create_user, create_model :attribute => 'value', ...

ModelFactory is available as a Rails plugin.
It provides a way to construct model objects from a configuration hash.

The special thing about ModelFactory is that it will also create belongs_to associates.

ModelFactory will first try to find the specified associated model object by id.
If the attempt to find it raises an not found error it will try to construct the 
specified associated model object from the configuration hash.


== Usage

  ModelFactory reads the required configuration information from a 
  MODEL_FACTORY_MODELS constant that is a hash you have to specify before the require statement in your
  helper file:
  
  MODEL_FACTORY_MODELS = {
    :user => {
      :attribute1 => 'value1',
      :attribute2 => 'value2',
    },
    :another_model => {
      :attribute => 'value'
    }
  }
  
  require 'model_factory'
  
  Now you can use the ModelFactory methods:
  
  create_user   # => #User attribute1=value1,  attribute2=value2
  
  create_model  # => #Model attribute=value
  
  create_model :user_id => 1 # => #Model attribute=value, user_id=1
  This will create a user object from the 
  MODEL_FACTORY_MODELS hash if there is no 
  user with id=1 in the database.
  
  
  
== INSTALL:

  $ ruby script/plugin install git://github.com/mhennemeyer/model_factory.git


Copyright (c) 2008 Matthias Hennemeyer, released under the MIT license
Something went wrong with that request. Please try again.