Add unit test and fix for crash during eviction of cache keys during query for compound identification attributes. closes #1171

This commit is contained in:
Blake Watters
2013-01-21 13:18:26 -05:00
parent abd207420b
commit 2351fc2472
2 changed files with 30 additions and 5 deletions

View File

@@ -226,7 +226,6 @@ static NSArray *RKCacheKeysForEntityFromAttributeValues(NSEntityDescription *ent
- (NSSet *)objectsWithAttributeValues:(NSDictionary *)attributeValues inContext:(NSManagedObjectContext *)context
{
// TODO: Assert that the attribute values contains all of the cache attributes!!!
NSMutableSet *objects = [NSMutableSet set];
NSArray *cacheKeys = RKCacheKeysForEntityFromAttributeValues(self.entity, attributeValues);
for (NSString *cacheKey in cacheKeys) {
@@ -281,10 +280,12 @@ static NSArray *RKCacheKeysForEntityFromAttributeValues(NSEntityDescription *ent
{
@synchronized(self.cacheKeysToObjectIDs) {
if (attributeValues && [attributeValues count]) {
NSString *cacheKey = RKCacheKeyForEntityWithAttributeValues(self.entity, attributeValues);
NSMutableArray *objectIDs = [self.cacheKeysToObjectIDs objectForKey:cacheKey];
if (objectIDs && [objectIDs containsObject:objectID]) {
[objectIDs removeObject:objectID];
NSArray *cacheKeys = RKCacheKeysForEntityFromAttributeValues(self.entity, attributeValues);
for (NSString *cacheKey in cacheKeys) {
NSMutableArray *objectIDs = [self.cacheKeysToObjectIDs objectForKey:cacheKey];
if (objectIDs && [objectIDs containsObject:objectID]) {
[objectIDs removeObject:objectID];
}
}
} else {
RKLogWarning(@"Unable to remove object for object ID %@: empty values dictionary for attributes '%@'", objectID, self.attributes);

View File

@@ -465,4 +465,28 @@
// trying to lookup with empty dictionary
// using weird attribute types as cache keys
- (void)testEvictionOfArrayOfIdentifierAttributes
{
// Put some objects into the cache
// Delete them
RKHuman *human1 = [NSEntityDescription insertNewObjectForEntityForName:@"Human" inManagedObjectContext:self.managedObjectContext];
human1.railsID = [NSNumber numberWithInteger:12345];
RKHuman *human2 = [NSEntityDescription insertNewObjectForEntityForName:@"Human" inManagedObjectContext:self.managedObjectContext];
human2.railsID = [NSNumber numberWithInteger:56789];
[self.managedObjectContext save:nil];
[self.cache addObject:human1];
[self.cache addObject:human2];
self.cache.monitorsContextForChanges = NO;
NSDictionary *attributeValues = @{ @"railsID" : @[ human1.railsID, human2.railsID ] };
[self.managedObjectContext deleteObject:human1];
[self.managedObjectContext deleteObject:human2];
[self.managedObjectContext save:nil];
[self.cache objectsWithAttributeValues:attributeValues inContext:self.managedObjectContext];
}
@end