Skip to content

Commit

Permalink
Adds failing test with other use case
Browse files Browse the repository at this point in the history
- That test fails on parse.com as well
  • Loading branch information
flovilmart committed May 29, 2016
1 parent 9b5761c commit e4abe61
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,4 +645,33 @@ describe('Cloud Code', () => {
done();
});
});

it('should fully delete objects when using `unset` with beforeSave (regression test for #1840)', done => {
var TestObject = Parse.Object.extend('TestObject');
var BeforeSaveObject = Parse.Object.extend('BeforeSaveChanged');

Parse.Cloud.beforeSave('BeforeSaveChanged', (req, res) => {
var object = req.object;
object.set('before', 'save');
object.unset('remove');
res.success();
});

let object;
let testObject = new TestObject({key: 'value'});
testObject.save().then(() => {
object = new BeforeSaveObject();
return object.save().then(() => {
object.set({remove:testObject})
return object.save();
});
}).then((objectAgain) => {
expect(objectAgain.get('remove')).toBeUndefined();
expect(object.get('remove')).toBeUndefined();
done();
}).fail((err) => {
console.error(err);
done();
})
});
});
2 changes: 1 addition & 1 deletion src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ function updateResponseWithData(response, data) {
let dataValue = data[fieldName];
let responseValue = response[fieldName];
if (dataValue && dataValue.__op === 'Delete') {
delete response[fieldName];
response[fieldName] = undefined;
} else {
response[fieldName] = responseValue || dataValue;
}
Expand Down

0 comments on commit e4abe61

Please sign in to comment.