Skip to content

Commit

Permalink
Merge pull request #784 from chrisleishman/splice_return
Browse files Browse the repository at this point in the history
Splice should return removed objects from array
  • Loading branch information
aheckmann committed Mar 21, 2012
2 parents a34731b + 0d87b11 commit 0613820
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/types/array.js
Expand Up @@ -306,9 +306,9 @@ MongooseArray.prototype.$pullAll = function (values) {
*/

MongooseArray.prototype.splice = function () {
[].splice.apply(this, arguments);
var result = [].splice.apply(this, arguments);
this._markModified();
return this;
return result;
};

/**
Expand Down
7 changes: 5 additions & 2 deletions test/types.array.test.js
Expand Up @@ -116,7 +116,8 @@ module.exports = {
should.equal(null, err, 'could not save splice test');
A.findById(a._id, function (err, doc) {
should.equal(null, err, 'error finding splice doc');
doc.numbers.splice(1, 1);
var removed = doc.numbers.splice(1, 1);
removed.should.eql([5]);
doc.numbers.toObject().should.eql([4,6,7]);
doc.save(function (err) {
should.equal(null, err, 'could not save splice test');
Expand Down Expand Up @@ -146,7 +147,9 @@ module.exports = {
A.findById(a._id, function (err, doc) {
should.equal(null, err, 'error finding splice doc');

doc.types.splice(1, 1);
var removed = doc.types.splice(1, 1);
removed.length.should.eql(1);
removed[0].type.should.eql('boy');

var obj = doc.types.toObject();
obj[0].type.should.eql('bird');
Expand Down

0 comments on commit 0613820

Please sign in to comment.