Created
April 29, 2012 07:10
-
-
Save nagyv/2538496 to your computer and use it in GitHub Desktop.
Testing mongoose pre-save with async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'), | |
async = require('async'), | |
Schema = mongoose.Schema, | |
ObjectId = Schema.ObjectId; | |
var MyS = new Schema({ | |
feeling: String | |
}); | |
MyS.pre('save', function(done){ | |
async.parallel([ | |
function(c1){c1();}, | |
function(c1){c1();} | |
], function(err, res) { | |
console.log('pre1'); | |
done(err); | |
}); | |
}); | |
MyS.pre('save', true, function(next, done){ | |
next(); | |
async.parallel([ | |
function(c1){c1();}, | |
function(c1){c1();} | |
], function(err, res) { | |
console.log('pre2'); | |
done(err); | |
}); | |
}); | |
var My = mongoose.model('My', MyS); | |
describe("Testing async pre-save with async included", function(){ | |
before(function(done){ | |
var uri; | |
uri = process.env.MONGOOSE_TEST_URI || | |
'mongodb://127.0.0.1:27017/test'; | |
mongoose.connect(uri); | |
this.db = mongoose.connection; | |
this.db.once('open', function(){ | |
done(); | |
}); | |
this.db.once('error', function (err) { | |
done(err); | |
}); | |
}); | |
after(function(){ | |
this.db.close(); | |
}); | |
it("should save the object", function(done){ | |
My.create({feeling: 'Love'}, function(err, stuff) { | |
console.log('created'); | |
done(err); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment