mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-12 22:51:50 +08:00
Add test coverage verifying that invalid objects blocking the Core Data save fails the object request operation. closes #969
This commit is contained in:
@@ -10,12 +10,12 @@
|
||||
#import "RKManagedObjectRequestOperation.h"
|
||||
#import "RKEntityMapping.h"
|
||||
#import "RKHuman.h"
|
||||
#import "RKMappingErrors.h"
|
||||
|
||||
@interface RKManagedObjectRequestOperation ()
|
||||
- (NSSet *)localObjectsFromFetchRequestsMatchingRequestURL:(NSError **)error;
|
||||
@end
|
||||
|
||||
|
||||
@interface RKManagedObjectRequestOperationTest : RKTestCase
|
||||
|
||||
@end
|
||||
@@ -150,4 +150,25 @@
|
||||
expect(mappedObjects[0]).to.equal(human);
|
||||
}
|
||||
|
||||
- (void)testThatInvalidObjectFailingManagedObjectContextSaveFailsOperation
|
||||
{
|
||||
// NOTE: The model defines a maximum length of 12 for the 'name' attribute
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.mainQueueManagedObjectContext];
|
||||
human.name = @"This Is An Invalid Name Because It Exceeds Twelve Characters";
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/JSON/humans/all.json" relativeToURL:[RKTestFactory baseURL]]];
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"name" toKeyPath:@"name"]];
|
||||
|
||||
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:humanMapping pathPattern:nil keyPath:@"human" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
|
||||
RKManagedObjectRequestOperation *managedObjectRequestOperation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
|
||||
managedObjectRequestOperation.managedObjectContext = managedObjectStore.mainQueueManagedObjectContext;
|
||||
|
||||
[managedObjectRequestOperation start];
|
||||
[managedObjectRequestOperation waitUntilFinished];
|
||||
expect(managedObjectRequestOperation.error).notTo.beNil();
|
||||
expect(managedObjectRequestOperation.mappingResult).to.beNil();
|
||||
expect([managedObjectRequestOperation.error localizedDescription]).to.equal(@"The operation couldn’t be completed. (Cocoa error 1660.)");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user