File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -232,10 +232,23 @@ - (BOOL)forEachLocalId:(BOOL(^)(PFObject *pointer))block error:(NSError **)error
232232 return YES ;
233233}
234234
235- - (BOOL )resolveLocalIds : (NSError **)error {
236- if (![self forEachLocalId: ^(PFObject *pointer) {
237- return [pointer resolveLocalId: nil ];
238- } error: error]) {
235+ - (BOOL )resolveLocalIds : (NSError * __autoreleasing *)error {
236+ __block NSError *firstError;
237+ __block BOOL pointerResolutionFailed = NO ;
238+ BOOL paramEncodingFailed = [self forEachLocalId: ^(PFObject *pointer) {
239+ NSError *localError;
240+ BOOL success = [pointer resolveLocalId: &localError];
241+ if (!success && !firstError) {
242+ firstError = localError;
243+ pointerResolutionFailed = YES ;
244+ }
245+ return YES ;
246+ } error: error];
247+ if (paramEncodingFailed && *error) {
248+ return NO ;
249+ }
250+ if (pointerResolutionFailed && firstError) {
251+ *error = firstError;
239252 return NO ;
240253 }
241254 [self maybeChangeServerOperation ];
Original file line number Diff line number Diff line change 1717#import " PFCommandURLRequestConstructor.h"
1818#import " PFRESTCommand.h"
1919#import " PFTestCase.h"
20+ #import " PFObject.h"
21+ #import " PFObjectPrivate.h"
2022#import " PFURLSession.h"
2123#import " PFURLSessionCommandRunner_Private.h"
2224
@@ -257,4 +259,14 @@ - (void)testLocalIdResolution {
257259 OCMVerifyAll (mockedCommand);
258260}
259261
262+ - (void )testLocalIdResolutionFailure {
263+ PFObject *object = [PFObject objectWithoutDataWithClassName: @" Yolo" localId: @" localId" ];
264+ id command = [PFRESTCommand commandWithHTTPPath: @" " httpMethod: @" " parameters: @{@" object" : object} sessionToken: nil error: nil ];
265+ NSError *error;
266+ [command resolveLocalIds: &error];
267+ XCTAssertNotNil (error);
268+ XCTAssertEqualObjects (error.domain , PFParseErrorDomain);
269+ XCTAssertEqualObjects (error.localizedDescription , @" Tried to save an object with a pointer to a new, unsaved object." );
270+ }
271+
260272@end
You can’t perform that action at this time.
0 commit comments