Add test case covering deletion of object before use in managed object request operation. refs #1252

This commit is contained in:
Blake Watters
2013-03-10 13:30:47 -04:00
parent dd74867c79
commit 2581d21762
2 changed files with 17 additions and 1 deletions

View File

@@ -386,7 +386,7 @@ static inline NSManagedObjectID *RKObjectIDFromObjectIfManaged(id object)
if (objectID) {
if ([objectID isTemporaryID]) RKLogWarning(@"Performing object mapping to temporary target objectID. Results may not be accessible without obtaining a permanent object ID.");
NSManagedObject *localObject = [self.managedObjectContext existingObjectWithID:objectID error:&blockError];
NSAssert(localObject == nil || [localObject.managedObjectContext isEqual:self.managedObjectContext], @"Serious Core Data error: requested existing object with ID %@ in context %@, instead got an object reference in context %@. This may indicate that the objectID for your target managed object was obtained using `obtainPermanentIDsForObjects:error:` in the wrong context.", objectID, self.managedObjectContext, [localObject managedObjectContext]);
NSAssert(localObject == nil || localObject.managedObjectContext == nil || [localObject.managedObjectContext isEqual:self.managedObjectContext], @"Serious Core Data error: requested existing object with ID %@ in context %@, instead got an object reference in context %@. This may indicate that the objectID for your target managed object was obtained using `obtainPermanentIDsForObjects:error:` in the wrong context.", objectID, self.managedObjectContext, [localObject managedObjectContext]);
if (! localObject) {
RKLogWarning(@"Failed to retrieve existing object with ID: %@", objectID);
RKLogCoreDataError(blockError);

View File

@@ -374,6 +374,22 @@ NSSet *RKSetByRemovingSubkeypathsFromSet(NSSet *setOfKeyPaths);
expect([human hasBeenDeleted]).to.equal(YES);
}
- (void)testThatDeletionOfObjectThatHasAlreadyBeenDeletedFromCoreDataDoesNotRaiseException
{
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
RKHuman *human = [RKTestFactory insertManagedObjectForEntityForName:@"Human" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext withProperties:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"/humans/success" relativeToURL:[RKTestFactory baseURL]]];
request.HTTPMethod = @"DELETE";
[managedObjectStore.persistentStoreManagedObjectContext saveToPersistentStore:nil];
RKManagedObjectRequestOperation *managedObjectRequestOperation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[]];
managedObjectRequestOperation.managedObjectContext = managedObjectStore.persistentStoreManagedObjectContext;
managedObjectRequestOperation.targetObject = human;
[managedObjectRequestOperation start];
[managedObjectRequestOperation waitUntilFinished];
expect(managedObjectRequestOperation.error).to.beNil();
expect([human hasBeenDeleted]).to.equal(YES);
}
- (void)testThatManagedObjectMappedAsTheRelationshipOfNonManagedObjectsAreRefetchedFromTheParentContext
{
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];