Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes mismatching behavior in including keys #777

Merged
merged 1 commit into from
Mar 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
// This is a port of the test suite:
// hungry/js/test/parse_object_test.js
//
Expand Down Expand Up @@ -1791,6 +1792,55 @@ describe('Parse.Object testing', () => {
console.error(err);
fail("should not fail");
done();
});
});

it('should have undefined includes when object is missing', (done) => {
let obj1 = new Parse.Object("AnObject");
let obj2 = new Parse.Object("AnObject");

Parse.Object.saveAll([obj1, obj2]).then(() => {
obj1.set("obj", obj2);
// Save the pointer, delete the pointee
return obj1.save().then(() => { return obj2.destroy() });
}).then(() => {
let query = new Parse.Query("AnObject");
query.include("obj");
return query.find();
}).then((res) => {
expect(res.length).toBe(1);
expect(res[0].get("obj")).toBe(undefined);
let query = new Parse.Query("AnObject");
return query.find();
}).then((res) => {
expect(res.length).toBe(1);
expect(res[0].get("obj")).not.toBe(undefined);
return res[0].get("obj").fetch();
}).then(() => {
fail("Should not fetch a deleted object");
}, (err) => {
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
done();
})
})
});

it('should have undefined includes when object is missing on deeper path', (done) => {
let obj1 = new Parse.Object("AnObject");
let obj2 = new Parse.Object("AnObject");
let obj3 = new Parse.Object("AnObject");
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
obj1.set("obj", obj2);
obj2.set("obj", obj3);
// Save the pointer, delete the pointee
return Parse.Object.saveAll([obj1, obj2]).then(() => { return obj3.destroy() });
}).then(() => {
let query = new Parse.Query("AnObject");
query.include("obj.obj");
return query.get(obj1.id);
}).then((res) => {
expect(res.get("obj")).not.toBe(undefined);
expect(res.get("obj").get("obj")).toBe(undefined);
done();
});
});
});
2 changes: 1 addition & 1 deletion src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ function replacePointers(object, path, replace) {
}

if (path.length == 0) {
if (object.__type == 'Pointer' && replace[object.objectId]) {
if (object.__type == 'Pointer') {
return replace[object.objectId];
}
return object;
Expand Down