Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplified tests

  • Loading branch information...
commit f05af80a42fb351758b1d7ea0f77954bfb029a32 1 parent b896c25
@chriseidhof authored
View
6 BandCamp.xcdatamodeld/BandCamp.xcdatamodel/contents
@@ -21,8 +21,8 @@
<attribute name="track_id" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
</entity>
<elements>
- <element name="Album" positionX="160" positionY="192" width="128" height="90"/>
- <element name="Band" positionX="160" positionY="192" width="128" height="135"/>
- <element name="Track" positionX="160" positionY="192" width="128" height="90"/>
+ <element name="Album" positionX="171" positionY="144" width="128" height="90"/>
+ <element name="Band" positionX="-0" positionY="144" width="128" height="135"/>
+ <element name="Track" positionX="349" positionY="144" width="128" height="90"/>
</elements>
</model>
View
39 IncrementalStoreTest/BandCampIS.m
@@ -43,7 +43,9 @@ - (BOOL)loadMetadata:(NSError**)error {
return YES;
}
-- (id)executeRequest:(NSPersistentStoreRequest*)request withContext:(NSManagedObjectContext*)context error:(NSError**)error {
+- (id)executeRequest:(NSPersistentStoreRequest*)request
+ withContext:(NSManagedObjectContext*)context
+ error:(NSError**)error {
if(request.requestType == NSFetchRequestType)
{
NSFetchRequest *fetchRequest = (NSFetchRequest*)request;
@@ -56,15 +58,20 @@ - (id)executeRequest:(NSPersistentStoreRequest*)request withContext:(NSManagedOb
return nil;
}
-- (id)fetchObjects:(NSFetchRequest*)request withContext:(NSManagedObjectContext*)context {
- NSArray* items = [BandCampAPI apiRequestEntitiesWithName:request.entityName predicate:request.predicate];
+- (id)fetchObjects:(NSFetchRequest*)request
+ withContext:(NSManagedObjectContext*)context {
+ NSArray* items = [BandCampAPI apiRequestEntitiesWithName:request.entityName
+ predicate:request.predicate];
return [items map:^(id item) {
- NSManagedObjectID* oid = [self objectIdForNewObjectOfEntity:request.entity cacheValues:item];
+ NSManagedObjectID* oid = [self objectIdForNewObjectOfEntity:request.entity
+ cacheValues:item];
return [context objectWithID:oid];
}];
}
-- (NSIncrementalStoreNode*)newValuesForObjectWithID:(NSManagedObjectID*)objectID withContext:(NSManagedObjectContext*)context error:(NSError**)error {
+- (NSIncrementalStoreNode*)newValuesForObjectWithID:(NSManagedObjectID*)objectID
+ withContext:(NSManagedObjectContext*)context
+ error:(NSError**)error {
NSDictionary* values = [cache objectForKey:objectID];
NSIncrementalStoreNode* node =
[[NSIncrementalStoreNode alloc] initWithObjectID:objectID
@@ -79,14 +86,12 @@ - (NSArray*)obtainPermanentIDsForObjects:(NSArray*)array error:(NSError**)error
}
- (id)newValueForRelationship:(NSRelationshipDescription*)relationship forObjectWithID:(NSManagedObjectID*)objectID withContext:(NSManagedObjectContext*)context error:(NSError**)error {
- NSString* entityName = relationship.entity.name;
- BOOL isDiscography = [entityName isEqualToString:@"Band"] && [relationship.name isEqualToString:@"discography"];
- BOOL isAlbumTracks = [entityName isEqualToString:@"Album"] && [relationship.name isEqualToString:@"tracks"];
-
- if(isDiscography) {
- return [self fetchDiscographyForBandWithId:objectID albumEntity:relationship.destinationEntity];
- } else if(isAlbumTracks) {
- return [self fetchTracksForAlbumWithId:objectID trackEntity:relationship.destinationEntity];
+ if([relationship.name isEqualToString:@"discography"]) {
+ return [self fetchDiscographyForBandWithId:objectID
+ albumEntity:relationship.destinationEntity];
+ } else if([relationship.name isEqualToString:@"tracks"]) {
+ return [self fetchTracksForAlbumWithId:objectID
+ trackEntity:relationship.destinationEntity];
}
NSLog(@"unknown relatioship: %@", relationship);
return nil;
@@ -94,7 +99,8 @@ - (id)newValueForRelationship:(NSRelationshipDescription*)relationship forObject
#pragma mark Relationship fetching
-- (NSArray*)fetchDiscographyForBandWithId:(NSManagedObjectID*)objectID albumEntity:(NSEntityDescription*)entity {
+- (NSArray*)fetchDiscographyForBandWithId:(NSManagedObjectID*)objectID
+ albumEntity:(NSEntityDescription*)entity {
id bandId = [self referenceObjectForObjectID:objectID];
NSArray* discographyData = [BandCampAPI apiDiscographyForBandWithId:bandId];
return [discographyData map:^(id album) {
@@ -115,10 +121,11 @@ - (NSArray*)fetchTracksForAlbumWithId:(NSManagedObjectID*)objectID trackEntity:(
#pragma mark Caching
- (NSManagedObjectID*)objectIdForNewObjectOfEntity:(NSEntityDescription*)entityDescription
- cacheValues:(NSDictionary*)values {
+ cacheValues:(NSDictionary*)values {
NSString* nativeKey = [self nativeKeyForEntityName:entityDescription.name];
id referenceId = [values objectForKey:nativeKey];
- NSManagedObjectID *objectId = [self newObjectIDForEntity:entityDescription referenceObject:referenceId];
+ NSManagedObjectID *objectId = [self newObjectIDForEntity:entityDescription
+ referenceObject:referenceId];
[cache setObject:values forKey:objectId];
return objectId;
}
Please sign in to comment.
Something went wrong with that request. Please try again.