Skip to content

Commit

Permalink
confirm gh-531 fix
Browse files Browse the repository at this point in the history
closes #531
  • Loading branch information
aheckmann committed Jul 6, 2012
1 parent 8c61503 commit 3e97790
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/types.document.test.js
Expand Up @@ -119,7 +119,7 @@ describe('types.document', function(){
assert.strictEqual(true, m.__id !== m2.__id);
});

it('Subdocument#remove', function (done) {
it('Subdocument#remove (gh-531)', function (done) {
var db = start();
var Movie = db.model('Movie');

Expand All @@ -134,7 +134,6 @@ describe('types.document', function(){
super8.ratings.push({ stars: 8, _id: id2 });
super8.ratings.push({ stars: 7, _id: id3 });
super8.ratings.push({ stars: 6, _id: id4 });
//console.error('pre save', super8);

super8.save(function (err) {
assert.ifError(err);
Expand Down Expand Up @@ -162,25 +161,30 @@ describe('types.document', function(){
assert.equal(movie.ratings.id(id3).stars.valueOf(), 4);
assert.equal(movie.ratings.id(id4).stars.valueOf(), 3);

//console.error('after save + findbyId', movie);

movie.ratings.id(id1).stars = 2;
movie.ratings.id(id3).remove();
movie.ratings.id(id4).stars = 1;

//console.error('after modified', movie);

movie.save(function (err) {
assert.ifError(err);

Movie.findById(super8._id, function (err, movie) {
db.close();
assert.ifError(err);
assert.equal(movie.ratings.length,2);
assert.equal(movie.ratings.id(id1).stars.valueOf(), 2);
assert.equal(movie.ratings.id(id4).stars.valueOf(), 1);
//console.error('after resave + findById', movie);
done();

// gh-531
movie.ratings[0].remove();
movie.ratings[0].remove();
movie.save(function (err) {
Movie.findById(super8._id, function (err, movie) {
db.close();
assert.ifError(err);
assert.equal(0, movie.ratings.length);
done();
});
});
});
});
});
Expand Down

0 comments on commit 3e97790

Please sign in to comment.