Skip to content

Instantly share code, notes, and snippets.

Created April 30, 2014 06:56
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
mongoose test post middleware
var Page = new Schema({
title: { type: String, default: '', trim: true },
url: { type: String, default: '', trim: true },
thumbnails: {type: Schema.ObjectId, ref: 'Thumbnails'},
});'save', function(doc) {
if(doc.thumbnails) return;
Thumbnail.generate(doc.url, function(err, thumb){
doc.thumbnails = thumb;
var Thumbnail = new Schema({
domain: {type: String, trim: true},
url: {
small: { type: String, trim: true },
original: {type: String, trim: true }
Thumbnail.statics.generate = function(doc, cb) {
// generate site preview , save the thumbnail and call cb
var Page = mongoose.model('Page');
var Thumbnail = mongoose.model('Thumbnail');
// How to verify post middleware ?
it("generates thumbnail if page does not have one", function(done){
var pageAttr = { title: 'Gist web page', url: '' }
var gist = new Page(pageAttr), function(err, _page){
if(err) throw err;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment