Skip to content

Commit f529c06

Browse files
committed
Fix missing file URL for short-circuited _User/_Session in RestWrite.
1 parent f461f2a commit f529c06

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

spec/ParseUser.spec.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ describe('Parse.User testing', () => {
8282
});
8383

8484
it("user login with files", (done) => {
85-
"use strict";
86-
8785
let file = new Parse.File("yolo.txt", [1,2,3], "text/plain");
8886
file.save().then((file) => {
8987
return Parse.User.signUp("asdf", "zxcv", { "file" : file });
@@ -930,6 +928,29 @@ describe('Parse.User testing', () => {
930928
});
931929
});
932930

931+
it('log in with provider with files', done => {
932+
let provider = getMockFacebookProvider();
933+
Parse.User._registerAuthenticationProvider(provider);
934+
let file = new Parse.File("yolo.txt", [1, 2, 3], "text/plain");
935+
file.save().then(file => {
936+
let user = new Parse.User();
937+
user.set('file', file);
938+
return user._linkWith('facebook', {});
939+
}).then(user => {
940+
expect(user._isLinked("facebook")).toBeTruthy();
941+
return Parse.User._logInWith('facebook', {});
942+
}).then(user => {
943+
let fileAgain = user.get('file');
944+
expect(fileAgain.name()).toMatch(/yolo.txt$/);
945+
expect(fileAgain.url()).toMatch(/yolo.txt$/);
946+
}).then(() => {
947+
done();
948+
}, error => {
949+
fail(error);
950+
done();
951+
});
952+
});
953+
933954
it("log in with provider twice", (done) => {
934955
var provider = getMockFacebookProvider();
935956
Parse.User._registerAuthenticationProvider(provider);

src/RestWrite.js

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ RestWrite.prototype.execute = function() {
7373
return this.validateAuthData();
7474
}).then(() => {
7575
return this.transformUser();
76+
}).then(() => {
77+
return this.expandFilesForExistingObjects();
7678
}).then(() => {
7779
return this.runDatabaseOperation();
7880
}).then(() => {
@@ -704,6 +706,16 @@ RestWrite.prototype.handleInstallation = function() {
704706
return promise;
705707
};
706708

709+
// If we short-circuted the object response - then we need to make sure we expand all the files,
710+
// since this might not have a query, meaning it won't return the full result back.
711+
// TODO: (nlutsenko) This should die when we move to per-class based controllers on _Session/_User
712+
RestWrite.prototype.expandFilesForExistingObjects = function() {
713+
// Check whether we have a short-circuited response - only then run expansion.
714+
if (this.response && this.response.response) {
715+
this.config.filesController.expandFilesInObject(this.config, this.response.response);
716+
}
717+
};
718+
707719
RestWrite.prototype.runDatabaseOperation = function() {
708720
if (this.response) {
709721
return;

0 commit comments

Comments
 (0)