Skip to content

Commit

Permalink
Added failing test where calling $push multiple times for an "update"…
Browse files Browse the repository at this point in the history
… doesn't convert the push elements to a pushAll.
  • Loading branch information
bnoguchi committed Feb 3, 2011
1 parent a677fa3 commit 22b2762
Showing 1 changed file with 12 additions and 40 deletions.
52 changes: 12 additions & 40 deletions test/model.test.js
Expand Up @@ -1462,7 +1462,7 @@ module.exports = {
});
},

'test saving multiple Number $pushes as a single $pushAll': function () {
'test updating multiple Number $pushes as a single $pushAll': function () {
var db = start()
, schema = new Schema({
nested: {
Expand All @@ -1473,50 +1473,22 @@ module.exports = {
mongoose.model('NestedPushes', schema);
var Temp = db.model('NestedPushes', collection);

var t = new Temp();

for (var i = 0; i < 100; i++) {
t.nested.nums.push(i);
}
Temp.create({}, function (err, t) {
t.nested.nums.push(1);
t.nested.nums.push(2);

t.nested.nums.should.have.length(100);
t.nested.nums.should.have.length(2);

t.save( function (err) {
should.strictEqual(null, err);
t.nested.nums.should.have.length(100);
Temp.findById(t._id, function (err, found) {
found.nested.nums.should.have.length(100);
db.close();
});
});
},

'test saving multiple ObjectId $pushes as a single $pushAll': function () {
var db = start()
, schema = new Schema({
nested: {
ids: [ObjectId]
}
t.save( function (err) {
should.strictEqual(null, err);
t.nested.nums.should.have.length(2);
Temp.findById(t._id, function (err, found) {
found.nested.nums.should.have.length(2);
db.close();
});

mongoose.model('NestedObjectIdPushes', schema);
var Temp = db.model('NestedObjectIdPushes', collection);

var t = new Temp();

t.nested.ids.push((new Temp())._id);
t.nested.ids.push((new Temp())._id);

t.nested.ids.should.have.length(2);

t.save( function (err) {
should.strictEqual(null, err);
t.nested.ids.should.have.length(2);
Temp.findById(t._id, function (err, found) {
found.nested.ids.should.have.length(2);
db.close();
});
});

},

'test saving embedded arrays of Numbers atomically': function () {
Expand Down

0 comments on commit 22b2762

Please sign in to comment.