mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-12 17:43:34 +08:00
Add test to verify managedObjectContext on empty results.
This commit is contained in:
@@ -933,6 +933,7 @@
|
||||
25FBB850159272DD00955D27 /* RKRouter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKRouter.h; sourceTree = "<group>"; };
|
||||
25FBB851159272DD00955D27 /* RKRouter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKRouter.m; sourceTree = "<group>"; };
|
||||
3E886DC0169E10A70069C56B /* has_many_with_to_one_relationship.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = has_many_with_to_one_relationship.json; sourceTree = "<group>"; };
|
||||
3EB0D83816ADCEFC00E9CEA2 /* empty_human.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = empty_human.json; sourceTree = "<group>"; };
|
||||
41A4EBF715374D1800740BC8 /* redirection.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = redirection.rb; sourceTree = "<group>"; };
|
||||
5C927E131608FFFD00DC8B07 /* RKDictionaryUtilitiesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKDictionaryUtilitiesTest.m; sourceTree = "<group>"; };
|
||||
5CCC295515B7124A0045F0F5 /* RKMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKMacros.h; sourceTree = "<group>"; };
|
||||
@@ -1382,6 +1383,7 @@
|
||||
children = (
|
||||
25160FE11456F2330060A5C5 /* 1.json */,
|
||||
25160FE21456F2330060A5C5 /* all.json */,
|
||||
3EB0D83816ADCEFC00E9CEA2 /* empty_human.json */,
|
||||
3E886DC0169E10A70069C56B /* has_many_with_to_one_relationship.json */,
|
||||
25160FE31456F2330060A5C5 /* with_to_one_relationship.json */,
|
||||
);
|
||||
|
||||
3
Tests/Fixtures/JSON/humans/empty_human.json
Normal file
3
Tests/Fixtures/JSON/humans/empty_human.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": null
|
||||
}
|
||||
@@ -1018,4 +1018,20 @@ NSSet *RKSetByRemovingSubkeypathsFromSet(NSSet *setOfKeyPaths);
|
||||
expect([user.bestFriend managedObjectContext]).to.equal(managedObjectStore.persistentStoreManagedObjectContext);
|
||||
}
|
||||
|
||||
- (void)testThatAnEmptyResultHasTheProperManagedObjectContext
|
||||
{
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:@"Human" inManagedObjectStore:managedObjectStore];
|
||||
[entityMapping addAttributeMappingsFromArray:@[ @"name" ]];
|
||||
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
|
||||
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/JSON/humans/empty_human.json" relativeToURL:[RKTestFactory baseURL]]];
|
||||
RKManagedObjectRequestOperation *managedObjectRequestOperation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ responseDescriptor ]];
|
||||
managedObjectRequestOperation.managedObjectContext = managedObjectStore.persistentStoreManagedObjectContext;
|
||||
[managedObjectRequestOperation start];
|
||||
expect(managedObjectRequestOperation.error).to.beNil();
|
||||
RKHuman *result = [managedObjectRequestOperation.mappingResult.array lastObject];
|
||||
expect(managedObjectRequestOperation.managedObjectContext).to.equal(result.managedObjectContext);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user