File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Parse/Internal/Object/State Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1515#import " PFMutableObjectState.h"
1616#import " PFObjectConstants.h"
1717#import " PFObjectUtilities.h"
18+ #import " PFFieldOperation.h"
1819
1920@implementation PFObjectState
2021
@@ -129,7 +130,11 @@ - (NSDictionary *)dictionaryRepresentationWithObjectEncoder:(PFEncoder *)objectE
129130#pragma mark Accessors
130131
131132- (void )setServerDataObject : (id )object forKey : (NSString *)key {
132- _serverData[key] = object;
133+ if (!object || [object isKindOfClass: [PFDeleteOperation class ]]) {
134+ [self removeServerDataObjectForKey: key];
135+ } else {
136+ _serverData[key] = object;
137+ }
133138}
134139
135140- (void )removeServerDataObjectForKey : (NSString *)key {
Original file line number Diff line number Diff line change @@ -45,6 +45,17 @@ - (void)testDecodingFieldOperations {
4545 XCTAssertEqualObjects (operation.amount , @100500 );
4646}
4747
48+ - (void )testDecodingDeleteOperation {
49+ PFDecoder *decoder = [[PFDecoder alloc ] init ];
50+
51+ NSDictionary *decoded = [decoder decodeObject: @{ @" key" : @{@" __op" : @" Delete" } }];
52+ XCTAssertNotNil (decoded);
53+
54+ id operation = decoded[@" key" ];
55+ XCTAssertNotNil (operation);
56+ PFAssertIsKindOfClass (operation, [PFDeleteOperation class ]);
57+ }
58+
4859- (void )testDecodingDates {
4960 PFDecoder *decoder = [[PFDecoder alloc ] init ];
5061
Original file line number Diff line number Diff line change @@ -166,6 +166,17 @@ - (void)testServerData {
166166 XCTAssertEqualObjects (mutableState.serverData , @{ @" foo" : @" bar" });
167167}
168168
169+ - (void )testDeleteFromServerData {
170+ PFMutableObjectState *mutableState = [[PFMutableObjectState alloc ] init ];
171+ XCTAssertEqualObjects (mutableState.serverData , @{});
172+
173+ [mutableState setServerDataObject: @" foo" forKey: @" bar" ];
174+ XCTAssertEqualObjects (mutableState.serverData , @{ @" bar" : @" foo" });
175+
176+ [mutableState setServerDataObject: [PFDeleteOperation new ] forKey: @" bar" ];
177+ XCTAssertEqualObjects (mutableState.serverData , @{});
178+ }
179+
169180- (void )testEncode {
170181 PFMutableObjectState *mutableState = [[PFMutableObjectState alloc ] init ];
171182 mutableState.objectId = @" objectId" ;
You can’t perform that action at this time.
0 commit comments