petejkim/factory-lady — pull request #13 by sogko (2014-01-26 14:49:10+00:00)
Title: Implemented dependent attribute (double handlebars)

Implemented dependent attribute support.
- Supports both dependent attribute defined as a string or as lazy attribute.
- Dependent attribute may also contain associations.
- Dependent attribute can also be passed as arguments to #build and #create.
- Using double handlebars as template tags.

See: https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#dependent-attributes

Definition example:
```
...
Factory.define('person', Person, {
name: function(cb) { cb("person " + nameCounter++); }
, age: 25
, job: Factory.assoc('job')
, title: Factory.assoc('job', 'title')
, job_description: Factory.assoc('job', 'description')
, job_description_alternate: Factory.assoc('job', 'description_alternate')
});

Factory.define('job', Job, {
title: 'Engineer'
, company: function(cb) { cb('Foobar Inc.'); }
, description: function(cb) { cb('{{title}} in {{company}}'); }
//--> "Engineer in Foobar Inc."
, description_alternate: '{{title}}, {{company}}'
// --> "Engineer, Foobar Inc."
});
```

Using it in factory#build example:
```
Factory.build( 'person',
{ name : 'John Doe, {{title}} - {{age}}' },
function(person) {
...
// person.title = 'Engineer'; <-- Note: person.title was defined as an association
// person.age = 25;
// person.name = 'John Doe, Engineer - 25';
}
);
```