File tree 3 files changed +28
-1
lines changed
Parse/Internal/Object/State
3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 15
15
#import " PFMutableObjectState.h"
16
16
#import " PFObjectConstants.h"
17
17
#import " PFObjectUtilities.h"
18
+ #import " PFFieldOperation.h"
18
19
19
20
@implementation PFObjectState
20
21
@@ -129,7 +130,11 @@ - (NSDictionary *)dictionaryRepresentationWithObjectEncoder:(PFEncoder *)objectE
129
130
#pragma mark Accessors
130
131
131
132
- (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
+ }
133
138
}
134
139
135
140
- (void )removeServerDataObjectForKey : (NSString *)key {
Original file line number Diff line number Diff line change @@ -45,6 +45,17 @@ - (void)testDecodingFieldOperations {
45
45
XCTAssertEqualObjects (operation.amount , @100500 );
46
46
}
47
47
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
+
48
59
- (void )testDecodingDates {
49
60
PFDecoder *decoder = [[PFDecoder alloc ] init ];
50
61
Original file line number Diff line number Diff line change @@ -166,6 +166,17 @@ - (void)testServerData {
166
166
XCTAssertEqualObjects (mutableState.serverData , @{ @" foo" : @" bar" });
167
167
}
168
168
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
+
169
180
- (void )testEncode {
170
181
PFMutableObjectState *mutableState = [[PFMutableObjectState alloc ] init ];
171
182
mutableState.objectId = @" objectId" ;
You can’t perform that action at this time.
0 commit comments