Skip to content

Instantly share code, notes, and snippets.

@pavlo-yuriychuk
Created January 30, 2015 12:38
Show Gist options
  • Save pavlo-yuriychuk/711bfe1013e0a66a57b3 to your computer and use it in GitHub Desktop.
Save pavlo-yuriychuk/711bfe1013e0a66a57b3 to your computer and use it in GitHub Desktop.
Morning@Lohika, Lviv
'use strict';
var should = require('should'),
modules = require('../index.js'),
models = modules.models,
fixtures = modules.fixtures,
MyModel = models.myModel;
describe('Cleanup Database', function() {
before(function(done) {
modules.init(function(err) {
if (err) {
done(err);
return;
}
fixtures.drop(function(err) {
done(err);
});
});
});
describe('MyModel collection', function() {
it('should be empty', function(done) {
Invite.find({}, function(error, result) {
should.not.exist(error);
should.exist(result);
result.should.have.length(0);
done();
});
});
});
});
'use strict';
var mongoose = require('mongoose'),
async = require('async'),
fakery = require('mongoose-fakery'),
myModel = require('../models');
module.exports = {
/**
* Drop all specified collections from database (if using mongodb)
*/
drop: function(collections, cb) {
if (typeof collections === 'function') {
cb = collections;
collections = [
'myModelCollection'
];
}
async.each(collections, function(collection, callback) {
if (mongoose.connection.collections[collection]) {
mongoose.connection.collections[collection].drop();
}
callback();
}, cb);
},
/**
* Create some invites for specified context
* @param cb
*/
insertModels: function(cb) {
var hex = fakery.g.hex;
fakery.fake('myModels', myModel.Model, {
refId: hex(24, 24),
likedToId: hex(24, 24),
surname: fakery.g.surname()
});
fakery.makeAndSave('myModels', cb);
}
};
'use strict';
var faker = require('faker');
// In order to create new message on each require
delete require.cache[require.resolve(__filename)];
module.exports = [{
'alias': faker.internet.email(),
'name': {
'first': faker.name.firstName(),
'last': faker.name.lastName()
},
'phones': {
'default': faker.phone.phoneNumber()
},
'addresses': {
'mailing': {
'street': faker.address.streetAddress(),
'city': faker.address.city(),
'state': faker.address.state(),
'postal': faker.address.zipCode(),
'country': faker.address.country()
}
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment