petejkim/factory-lady — pull request #15 by aexmachina (2014-04-09 03:42:06+00:00)
Title: Added support for using adapters to provide support for different persistence layers

Also includes a default Adapter that provides backwards compatibility.

Here's an example adapter for `sequelize`:

```
var Factory = require('factory-lady'),
Adapter = Factory.Adapter;

var SequelizeAdapter = function() {};
SequelizeAdapter.prototype = new Adapter();
SequelizeAdapter.prototype.create = function(Model, props) {
return Model.build(props);
};
SequelizeAdapter.prototype.save = function(doc, Model, cb) {
doc.save()
.success(function() {
cb();
})
.error(function(event) {
var err = new Error('Failed to save fixture');
err.event = event;
cb(err);
});
};

var adapter = new SequelizeAdapter();
Factory.setAdapter(adapter);
```