Skip to content

Commit

Permalink
add test for passing objects to Document#set
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed May 19, 2011
1 parent 2d33955 commit c243d10
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/mongoose/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoose/schema/documentarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions test/types.document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.