Permalink
Browse files

the test

  • Loading branch information...
Mihai Chiorean Aaron Heckmann
Mihai Chiorean authored and Aaron Heckmann committed Jan 16, 2014
1 parent 7d6729c commit b51b1e8306a4f437f754b85109af948d17c555e7
Showing with 36 additions and 1 deletion.
  1. +1 −1 lib/model.js
  2. +35 −0 test/model.populate.test.js
View
@@ -2060,7 +2060,7 @@ Model.populate = function (docs, paths, cb) {
var model = this;
while (i--) {
path = paths[i];
- if ('function' == typeof path && path.model) model = path.model;
+ if ('function' === typeof path.model) model = path.model;
populate(model, docs, path, next);
}
@@ -56,6 +56,7 @@ mongoose.model('RefBlogPost', BlogPost);
mongoose.model('RefUser', User);
mongoose.model('RefAlternateUser', User);
+
/**
* Tests.
*/
@@ -94,6 +95,40 @@ describe('model: populate:', function(){
});
})
+ it('across DBs', function(done) {
+ var db = start()
+ , db2 = mongoose.createConnection('mongodb://localhost/mongoose_test2')
+ , BlogPost = db.model('RefBlogPost', posts + '2')
+ , User = db2.model('RefUser', users + '2');
+
+ User.create({
+ name: 'Guillermo'
+ , email: 'rauchg@gmail.com'
+ }, function (err, creator) {
+ console.dir(creator);
+ assert.ifError(err);
+
+ BlogPost.create({
+ title : 'woot'
+ , _creator : creator._id
+ }, function (err, post) {
+ assert.ifError(err);
+ BlogPost
+ .findById(post._id)
+ .populate('_creator', 'name', User)
+ .exec(function (err, post) {
+ db.close();
+ db2.close();
+ assert.ifError(err);
+ console.log(post.title);
+ console.dir(post);
+ assert.ok(post._creator.name == 'Guillermo');
+ done()
+ });
+ });
+ })
+ })
+
it('an error in single ref population propagates', function(done){
var db = start()
, BlogPost = db.model('RefBlogPost', posts + '1')

0 comments on commit b51b1e8

Please sign in to comment.