diff --git a/RestKit.xcodeproj/project.pbxproj b/RestKit.xcodeproj/project.pbxproj index cec620ae..78a69bc6 100644 --- a/RestKit.xcodeproj/project.pbxproj +++ b/RestKit.xcodeproj/project.pbxproj @@ -933,6 +933,7 @@ 25FBB850159272DD00955D27 /* RKRouter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKRouter.h; sourceTree = ""; }; 25FBB851159272DD00955D27 /* RKRouter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKRouter.m; sourceTree = ""; }; 3E886DC0169E10A70069C56B /* has_many_with_to_one_relationship.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = has_many_with_to_one_relationship.json; sourceTree = ""; }; + 3EB0D83816ADCEFC00E9CEA2 /* empty_human.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = empty_human.json; sourceTree = ""; }; 41A4EBF715374D1800740BC8 /* redirection.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = redirection.rb; sourceTree = ""; }; 5C927E131608FFFD00DC8B07 /* RKDictionaryUtilitiesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKDictionaryUtilitiesTest.m; sourceTree = ""; }; 5CCC295515B7124A0045F0F5 /* RKMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKMacros.h; sourceTree = ""; }; @@ -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 */, ); diff --git a/Tests/Fixtures/JSON/humans/empty_human.json b/Tests/Fixtures/JSON/humans/empty_human.json new file mode 100644 index 00000000..0d4dc5a1 --- /dev/null +++ b/Tests/Fixtures/JSON/humans/empty_human.json @@ -0,0 +1,3 @@ +{ + "name": null +} \ No newline at end of file diff --git a/Tests/Logic/Network/RKManagedObjectRequestOperationTest.m b/Tests/Logic/Network/RKManagedObjectRequestOperationTest.m index 9e35e951..ac012cd7 100644 --- a/Tests/Logic/Network/RKManagedObjectRequestOperationTest.m +++ b/Tests/Logic/Network/RKManagedObjectRequestOperationTest.m @@ -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