https://github.com/cpg1111/factorydude
A Node module to create mongoose objects for test data
https://github.com/cpg1111/factorydude
Last synced: 27 days ago
JSON representation
A Node module to create mongoose objects for test data
- Host: GitHub
- URL: https://github.com/cpg1111/factorydude
- Owner: cpg1111
- License: apache-2.0
- Created: 2015-01-16T03:53:37.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-03T14:07:19.000Z (about 11 years ago)
- Last Synced: 2025-07-10T09:32:59.537Z (11 months ago)
- Language: JavaScript
- Size: 253 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FactoryDude
A Node module to create mongoose objects for test data
[](https://gitter.im/cpg1111/FactoryDude?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

To be used in test suites (mocha, chai, jasmine, etc) for features that use mongoose models.
Inspired by factory_girl
### Install
```
npm install FactoryDude
```
## Usage
```
var FactoryDude = require('FactoryDude');
var factoryDude = new FactoryDude();
```
### Create a Factory
```
var newFixtureModel = factoryDude.factory(
,
,
);
/*
* returns a mongoose model that has been saved in the database
* and can be used just as any other mongoose models.
*/
```
### Reference one factory in another factory
```
factoryDude.reference(, );
```
```
var firstFixtureModel = factoryDude.factory(
'firstModel',
'./path/to/model',
{name: 'test', number: 1}
);
//creates a model with the name test and a number 1
var secondFixtureModel = factoryDude.factory(
'secondModel',
'./path/to/model',
{name: factoryDude.reference('firstModel', 'name'), number: 2}
);
//creates a model with the name test and a number 2
```
### Destroy a factory model that was already created
```
factoryDude.destroy();
```
```
var firstFixtureModel = factoryDude.factory(
'firstModel',
'./path/to/model',
{name: 'test', number: 1}
);
factoryDude.destroy('firstModel'); //'firstModel' is no longer in the database or a fixture
```
## License
FactoryDude is licensed under the apache license.