Adds support for plain object in $add, $addUnique, $remove
This commit is contained in:
@@ -600,6 +600,49 @@ describe('Parse.Object testing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("addUnique with object", function(done) {
|
||||||
|
var x1 = new Parse.Object('X');
|
||||||
|
x1.set('stuff', [ 1, {'hello': 'world'}, {'foo': 'bar'}]);
|
||||||
|
x1.save().then(() => {
|
||||||
|
var objectId = x1.id;
|
||||||
|
var x2 = new Parse.Object('X', {objectId: objectId});
|
||||||
|
x2.addUnique('stuff', {'hello': 'world'});
|
||||||
|
x2.addUnique('stuff', {'bar': 'baz'});
|
||||||
|
expect(x2.get('stuff')).toEqual([{'hello': 'world'}, {'bar': 'baz'}]);
|
||||||
|
return x2.save();
|
||||||
|
}).then(() => {
|
||||||
|
var query = new Parse.Query('X');
|
||||||
|
return query.get(x1.id);
|
||||||
|
}).then((x3) => {
|
||||||
|
expect(x3.get('stuff')).toEqual([1, {'hello': 'world'}, {'foo': 'bar'}, {'bar': 'baz'}]);
|
||||||
|
done();
|
||||||
|
}, (error) => {
|
||||||
|
fail(error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes with object", function(done) {
|
||||||
|
var x1 = new Parse.Object('X');
|
||||||
|
x1.set('stuff', [ 1, {'hello': 'world'}, {'foo': 'bar'}]);
|
||||||
|
x1.save().then(() => {
|
||||||
|
var objectId = x1.id;
|
||||||
|
var x2 = new Parse.Object('X', {objectId: objectId});
|
||||||
|
x2.remove('stuff', {'hello': 'world'});
|
||||||
|
expect(x2.get('stuff')).toEqual([]);
|
||||||
|
return x2.save();
|
||||||
|
}).then(() => {
|
||||||
|
var query = new Parse.Query('X');
|
||||||
|
return query.get(x1.id);
|
||||||
|
}).then((x3) => {
|
||||||
|
expect(x3.get('stuff')).toEqual([1, {'foo': 'bar'}]);
|
||||||
|
done();
|
||||||
|
}, (error) => {
|
||||||
|
fail(error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("dirty attributes", function(done) {
|
it("dirty attributes", function(done) {
|
||||||
var object = new Parse.Object("TestObject");
|
var object = new Parse.Object("TestObject");
|
||||||
object.set("cat", "good");
|
object.set("cat", "good");
|
||||||
@@ -1794,14 +1837,14 @@ describe('Parse.Object testing', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have undefined includes when object is missing', (done) => {
|
it('should have undefined includes when object is missing', (done) => {
|
||||||
let obj1 = new Parse.Object("AnObject");
|
let obj1 = new Parse.Object("AnObject");
|
||||||
let obj2 = new Parse.Object("AnObject");
|
let obj2 = new Parse.Object("AnObject");
|
||||||
|
|
||||||
Parse.Object.saveAll([obj1, obj2]).then(() => {
|
Parse.Object.saveAll([obj1, obj2]).then(() => {
|
||||||
obj1.set("obj", obj2);
|
obj1.set("obj", obj2);
|
||||||
// Save the pointer, delete the pointee
|
// Save the pointer, delete the pointee
|
||||||
return obj1.save().then(() => { return obj2.destroy() });
|
return obj1.save().then(() => { return obj2.destroy() });
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
let query = new Parse.Query("AnObject");
|
let query = new Parse.Query("AnObject");
|
||||||
@@ -1823,7 +1866,7 @@ describe('Parse.Object testing', () => {
|
|||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have undefined includes when object is missing on deeper path', (done) => {
|
it('should have undefined includes when object is missing on deeper path', (done) => {
|
||||||
let obj1 = new Parse.Object("AnObject");
|
let obj1 = new Parse.Object("AnObject");
|
||||||
let obj2 = new Parse.Object("AnObject");
|
let obj2 = new Parse.Object("AnObject");
|
||||||
@@ -1831,7 +1874,7 @@ describe('Parse.Object testing', () => {
|
|||||||
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
|
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
|
||||||
obj1.set("obj", obj2);
|
obj1.set("obj", obj2);
|
||||||
obj2.set("obj", obj3);
|
obj2.set("obj", obj3);
|
||||||
// Save the pointer, delete the pointee
|
// Save the pointer, delete the pointee
|
||||||
return Parse.Object.saveAll([obj1, obj2]).then(() => { return obj3.destroy() });
|
return Parse.Object.saveAll([obj1, obj2]).then(() => { return obj3.destroy() });
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
let query = new Parse.Query("AnObject");
|
let query = new Parse.Query("AnObject");
|
||||||
|
|||||||
@@ -398,6 +398,9 @@ function transformAtom(atom, force, options) {
|
|||||||
if (FileCoder.isValidJSON(atom)) {
|
if (FileCoder.isValidJSON(atom)) {
|
||||||
return (inArray || inObject ? atom : FileCoder.JSONToDatabase(atom));
|
return (inArray || inObject ? atom : FileCoder.JSONToDatabase(atom));
|
||||||
}
|
}
|
||||||
|
if (inArray || inObject) {
|
||||||
|
return atom;
|
||||||
|
}
|
||||||
|
|
||||||
if (force) {
|
if (force) {
|
||||||
throw new Parse.Error(Parse.Error.INVALID_JSON,
|
throw new Parse.Error(Parse.Error.INVALID_JSON,
|
||||||
|
|||||||
Reference in New Issue
Block a user