0.0.1 • Published 8 years ago

uj-mongoose-fixtures v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

mongoose-fixtures

Build Status

This library aims to provide a simple way to manage and execute the loading of data fixtures for the mongoose. Here is a simple example of a fixture:

// fixtures/user-fixture.js
module.exports = function(conn, references) {
	User = conn.model('User');
	var user = new User({...})
	return user.save();
};

A fixture is any callback which returns a promise. The promise should be resolved when all the fixtures data are loaded to the database.

Then you need to add fixtures to a loader instance:

var loader = require('mongoose-fixtures').loader();
loader.load(require('fixtures/user-fixture'));

You can load a set of fixtures from a directory as well:

var path = require('path');

loader.loadFromDirectory(path.resolve(__dirname, './fixtures'));

Then you can execute the fixtures:

var mongoose = require('mongoose'),
  executor = require('mongoose-fixtures').executor(mongoose);
  
executor.execute(loader);

Running the tests

  • clone the repo and go to the root directory of the repo
  • npm install
  • npm test