Tests for update/upsert with $push/$each.

Test adapted by mcbain's test from #1492.
This commit is contained in:
David Glasser
2013-10-18 15:39:47 -07:00
parent 5a8ab31f43
commit dcfd00fe2f
2 changed files with 55 additions and 1 deletions

View File

@@ -3,7 +3,7 @@
* Fail explicitly when publishing non-cursors. * Fail explicitly when publishing non-cursors.
* Implement `$each`, `$sort`, and `$slice` options for minimongo's `$push` * Implement `$each`, `$sort`, and `$slice` options for minimongo's `$push`
modifier. modifier. #1492
* Increase the maximum size spiderable will return for a page from 200kB * Increase the maximum size spiderable will return for a page from 200kB
to 5MB. to 5MB.
@@ -11,6 +11,8 @@
* Upgraded dependencies: * Upgraded dependencies:
* SockJS server from 0.3.7 to 0.3.8 * SockJS server from 0.3.7 to 0.3.8
Patches contributed by GitHub user mcbain.
## v0.6.6.1 ## v0.6.6.1

View File

@@ -1815,3 +1815,55 @@ Tinytest.addAsync("mongo-livedata - local collection with null connection, w/o c
test.equal(coll1.findOne(doc)._id, docId); test.equal(coll1.findOne(doc)._id, docId);
onComplete(); onComplete();
}); });
Tinytest.add("mongo-livedata - update handles $push with $each correctly", function (test) {
var collection = new Meteor.Collection(Random.id());
var id = collection.insert({name: 'jens', elements: ['X', 'Y']});
var result = collection.update(id, {
$push: {
elements: {
$each: ['A', 'B', 'C'],
$slice: -4
}}});
test.equal(collection.findOne(id), {
_id: id,
name: 'jens',
elements: ['Y', 'A', 'B', 'C']
});
});
if (Meteor.isServer) {
Tinytest.add("mongo-livedata - upsert handles $push with $each correctly", function (test) {
var collection = new Meteor.Collection(Random.id());
var result = collection.upsert(
{name: 'jens'},
{$push: {
elements: {
$each: ['A', 'B', 'C'],
$slice: -4
}}});
test.equal(collection.findOne(result.insertedId),
{_id: result.insertedId,
name: 'jens',
elements: ['A', 'B', 'C']});
var id = collection.insert({name: "david", elements: ['X', 'Y']});
result = collection.upsert(
{name: 'david'},
{$push: {
elements: {
$each: ['A', 'B', 'C'],
$slice: -4
}}});
test.equal(collection.findOne(id),
{_id: id,
name: 'david',
elements: ['Y', 'A', 'B', 'C']});
});
}