Skip to content
Browse files

add test for passing objects to Document#set

  • Loading branch information...
1 parent 2d33955 commit c243d102324d7dfc3779879be0028b5f134aa834 @aheckmann aheckmann committed May 19, 2011
Showing with 12 additions and 1 deletion.
  1. +4 −0 lib/mongoose/document.js
  2. +1 −1 lib/mongoose/schema/documentarray.js
  3. +7 −0 test/types.document.test.js
View
4 lib/mongoose/document.js
@@ -203,6 +203,10 @@ Document.prototype.set = function (path, val, type) {
? val + '.'
: '';
+ if (path instanceof Document) {
+ path = path.doc;
+ }
+
var keys = Object.keys(path);
var i = keys.length;
var key;
View
2 lib/mongoose/schema/documentarray.js
@@ -92,7 +92,7 @@ DocumentArray.prototype.cast = function (value, doc) {
for (var i = 0, l = value.length; i < l; i++)
if (!(value[i] instanceof Subdocument)){
var doc = new this.caster(null, value);
- value[i] = doc.init(value[i]);
+ value[i] = doc.init(value[i].doc || value[i]);
}
return value;
View
7 test/types.document.test.js
@@ -60,6 +60,13 @@ module.exports = {
a.save(function(err){
should.strictEqual(err, null);
});
+ },
+
+ 'objects can be passed to #set': function () {
+ var a = new Subdocument();
+ a.set({ test: 'paradiddle', work: 'good flam'});
+ a.test.should.eql('paradiddle');
+ a.work.should.eql('good flam');
}
};

0 comments on commit c243d10

Please sign in to comment.
Something went wrong with that request. Please try again.