mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Pass through the return value for update and remove on validated operations.
Fixes #1759.
This commit is contained in:
@@ -421,6 +421,7 @@ if (Meteor.isClient) {
|
||||
{$set: {updated: true}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 1);
|
||||
test.equal(collection.find({updated: true}).count(), 1);
|
||||
}));
|
||||
},
|
||||
@@ -431,6 +432,7 @@ if (Meteor.isClient) {
|
||||
{$set: {updated: true}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 1);
|
||||
test.equal(collection.find({updated: true}).count(), 2);
|
||||
}));
|
||||
},
|
||||
@@ -603,6 +605,7 @@ if (Meteor.isClient) {
|
||||
canUpdateId, {$set: {"dotted.field": 1}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 1);
|
||||
test.equal(collection.findOne(canUpdateId).dotted.field, 1);
|
||||
}));
|
||||
},
|
||||
@@ -622,6 +625,7 @@ if (Meteor.isClient) {
|
||||
{$set: {updated: true}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 0);
|
||||
// nothing has changed
|
||||
test.equal(collection.find().count(), 3);
|
||||
test.equal(collection.find({updated: true}).count(), 0);
|
||||
@@ -670,6 +674,7 @@ if (Meteor.isClient) {
|
||||
{$set: {updated: true}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 1);
|
||||
test.equal(collection.find({updated: true}).count(), 1);
|
||||
}));
|
||||
},
|
||||
@@ -701,6 +706,7 @@ if (Meteor.isClient) {
|
||||
{$set: {cantRemove: false, canUpdate2: true}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 1);
|
||||
test.equal(collection.find({cantRemove: true}).count(), 0);
|
||||
}));
|
||||
},
|
||||
@@ -710,11 +716,23 @@ if (Meteor.isClient) {
|
||||
collection.remove(canRemoveId,
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 1);
|
||||
// successfully removed
|
||||
test.equal(collection.find().count(), 2);
|
||||
}));
|
||||
},
|
||||
|
||||
// try to remove a doc that doesn't exist. see we remove no docs.
|
||||
function (test, expect) {
|
||||
collection.remove('some-random-id-that-never-matches',
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(res, 0);
|
||||
// nothing removed
|
||||
test.equal(collection.find().count(), 2);
|
||||
}));
|
||||
},
|
||||
|
||||
// methods can still bypass restrictions
|
||||
function (test, expect) {
|
||||
collection.callClearMethod(
|
||||
|
||||
@@ -780,7 +780,7 @@ Meteor.Collection.prototype._validatedUpdate = function(
|
||||
|
||||
var doc = self._collection.findOne(selector, findOptions);
|
||||
if (!doc) // none satisfied!
|
||||
return;
|
||||
return 0;
|
||||
|
||||
var factoriedDoc;
|
||||
|
||||
@@ -813,7 +813,7 @@ Meteor.Collection.prototype._validatedUpdate = function(
|
||||
// avoid races, but since selector is guaranteed to already just be an ID, we
|
||||
// don't have to any more.
|
||||
|
||||
self._collection.update.call(
|
||||
return self._collection.update.call(
|
||||
self._collection, selector, mutator, options);
|
||||
};
|
||||
|
||||
@@ -843,7 +843,7 @@ Meteor.Collection.prototype._validatedRemove = function(userId, selector) {
|
||||
|
||||
var doc = self._collection.findOne(selector, findOptions);
|
||||
if (!doc)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
// call user validators.
|
||||
// Any deny returns true means denied.
|
||||
@@ -864,5 +864,5 @@ Meteor.Collection.prototype._validatedRemove = function(userId, selector) {
|
||||
// Mongo to avoid races, but since selector is guaranteed to already just be
|
||||
// an ID, we don't have to any more.
|
||||
|
||||
self._collection.remove.call(self._collection, selector);
|
||||
return self._collection.remove.call(self._collection, selector);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user