Skip to content

Let the iOS SDK handle Delete ops when sent from the server #928

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

Merged
merged 1 commit into from
Jun 19, 2017
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
7 changes: 6 additions & 1 deletion Parse/Internal/Object/State/PFObjectState.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "PFMutableObjectState.h"
#import "PFObjectConstants.h"
#import "PFObjectUtilities.h"
#import "PFFieldOperation.h"

@implementation PFObjectState

Expand Down Expand Up @@ -129,7 +130,11 @@ - (NSDictionary *)dictionaryRepresentationWithObjectEncoder:(PFEncoder *)objectE
#pragma mark Accessors

- (void)setServerDataObject:(id)object forKey:(NSString *)key {
_serverData[key] = object;
if (!object || [object isKindOfClass:[PFDeleteOperation class]]) {
[self removeServerDataObjectForKey:key];
} else {
_serverData[key] = object;
}
}

- (void)removeServerDataObjectForKey:(NSString *)key {
Expand Down
11 changes: 11 additions & 0 deletions Tests/Unit/DecoderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ - (void)testDecodingFieldOperations {
XCTAssertEqualObjects(operation.amount, @100500);
}

- (void)testDecodingDeleteOperation {
PFDecoder *decoder = [[PFDecoder alloc] init];

NSDictionary *decoded = [decoder decodeObject:@{ @"key" : @{@"__op" : @"Delete"} }];
XCTAssertNotNil(decoded);

id operation = decoded[@"key"];
XCTAssertNotNil(operation);
PFAssertIsKindOfClass(operation, [PFDeleteOperation class]);
}

- (void)testDecodingDates {
PFDecoder *decoder = [[PFDecoder alloc] init];

Expand Down
11 changes: 11 additions & 0 deletions Tests/Unit/ObjectStateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ - (void)testServerData {
XCTAssertEqualObjects(mutableState.serverData, @{ @"foo": @"bar" });
}

- (void)testDeleteFromServerData {
PFMutableObjectState *mutableState = [[PFMutableObjectState alloc] init];
XCTAssertEqualObjects(mutableState.serverData, @{});

[mutableState setServerDataObject:@"foo" forKey:@"bar"];
XCTAssertEqualObjects(mutableState.serverData, @{ @"bar": @"foo" });

[mutableState setServerDataObject:[PFDeleteOperation new] forKey:@"bar"];
XCTAssertEqualObjects(mutableState.serverData, @{});
}

- (void)testEncode {
PFMutableObjectState *mutableState = [[PFMutableObjectState alloc] init];
mutableState.objectId = @"objectId";
Expand Down