Skip to content
Browse files

Ensure managed object loader instances are finalized on failure to sa…

…ve managed object store. closes #721
  • Loading branch information...
1 parent c3eeeea commit ee30436ea64ecfeff173912afaa3193ebb6a7f6c @blakewatters blakewatters committed May 17, 2012
View
4 Code/CoreData/RKManagedObjectLoader.m
@@ -171,6 +171,10 @@ - (void)processMappingResult:(RKObjectMappingResult*)result {
[invocation setSelector:@selector(informDelegateOfError:)];
[invocation setArgument:&error atIndex:2];
[invocation invokeOnMainThread];
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self finalizeLoad:success];
+ });
return;
}
}
View
1 Code/Network/RKRequest_Internals.h
@@ -21,4 +21,5 @@
@interface RKRequest (Internals)
- (BOOL)prepareURLRequest;
- (void)didFailLoadWithError:(NSError*)error;
+- (void)finalizeLoad:(BOOL)successful;
@end
View
4 Code/Testing/RKTestResponseLoader.m
@@ -151,6 +151,10 @@ - (void)objectLoaderDidLoadUnexpectedResponse:(RKObjectLoader *)objectLoader {
unexpectedResponse = YES;
}
+- (void)objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader {
+ // Implemented for expectations
+}
+
#pragma mark - OAuth delegates
- (void)OAuthClient:(RKOAuthClient *)client didAcquireAccessToken:(NSString *)token {
View
21 Tests/Logic/CoreData/RKManagedObjectLoaderTest.m
@@ -214,4 +214,25 @@ - (void)testTheOnDidFailBlockIsInvokedOnFailure {
assertThatBool(invoked, is(equalToBool(YES)));
}
+- (void)testThatObjectLoadedDidFinishLoadingIsCalledOnStoreSaveFailure {
+ RKManagedObjectStore* store = [RKTestFactory managedObjectStore];
+ RKObjectManager* objectManager = [RKTestFactory objectManager];
+ objectManager.objectStore = store;
+ id mockStore = [OCMockObject partialMockForObject:store];
+ BOOL success = NO;
+ [[[mockStore stub] andReturnValue:OCMOCK_VALUE(success)] save:[OCMArg anyPointer]];
+
+ RKObjectMapping* mapping = [RKManagedObjectMapping mappingForClass:[RKHuman class] inManagedObjectStore:store];
+ RKManagedObjectLoader* objectLoader = [objectManager loaderWithResourcePath:@"/humans/1"];
+ objectLoader.objectMapping = mapping;
+
+ RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
+ id mockResponseLoader = [OCMockObject partialMockForObject:responseLoader];
+ [[mockResponseLoader expect] objectLoaderDidFinishLoading:objectLoader];
+ objectLoader.delegate = responseLoader;
+ [objectLoader sendAsynchronously];
+ [responseLoader waitForResponse];
+ [mockResponseLoader verify];
+}
+
@end

0 comments on commit ee30436

Please sign in to comment.
Something went wrong with that request. Please try again.