Files
RestKit/Tests/Logic/CoreData/RKFetchRequestMappingCacheTest.m
Blake Watters 79e31b524a Refactored managed object caches and connection support to enable connecting by multiple atributes that are specified as arrays.
* Migrated the caches to return `NSSet` to eliminate duplicate objects when your cache keys overlap
* Introduced new recursive strategy for building cache keys in `RKInMemoryManagedObjectCache`
* Added support for array cache key values in `RKFetchRequestManagedObjectCache`
* Re-enabled a slew of tests that were disabled during 0.20 development
2012-12-06 23:43:34 -05:00

61 lines
2.9 KiB
Objective-C

//
// RKFetchRequestMappingTest.m
// RestKit
//
// Created by Blake Watters on 3/20/12.
// Copyright (c) 2009-2012 RestKit. All rights reserved.
//
#import "RKTestEnvironment.h"
#import "RKCat.h"
#import "RKEvent.h"
@interface RKFetchRequestMappingCacheTest : RKTestCase
@end
@implementation RKFetchRequestMappingCacheTest
- (void)testFetchRequestMappingCacheReturnsObjectsWithNumericPrimaryKey
{
// RKCat entity. Integer prinmary key.
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
RKFetchRequestManagedObjectCache *cache = [RKFetchRequestManagedObjectCache new];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Cat" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Cat" inManagedObjectStore:managedObjectStore];
mapping.identificationAttributes = @[ @"railsID" ];
RKCat *reginald = [NSEntityDescription insertNewObjectForEntityForName:@"Cat" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
reginald.name = @"Reginald";
reginald.railsID = [NSNumber numberWithInt:123456];
[managedObjectStore.persistentStoreManagedObjectContext save:nil];
NSSet *managedObjects = [cache managedObjectsWithEntity:entity
attributeValues:@{ @"railsID": @123456 }
inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
NSSet *cats = [NSSet setWithObject:reginald];
expect(managedObjects).to.equal(cats);
}
- (void)testFetchRequestMappingCacheReturnsObjectsWithStringPrimaryKey
{
// RKEvent entity. String primary key
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
RKFetchRequestManagedObjectCache *cache = [RKFetchRequestManagedObjectCache new];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:managedObjectStore];
mapping.identificationAttributes = @[ @"eventID" ];
RKEvent *birthday = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
birthday.eventID = @"e-1234-a8-b12";
[managedObjectStore.persistentStoreManagedObjectContext save:nil];
NSSet *managedObjects = [cache managedObjectsWithEntity:entity
attributeValues:@{ @"eventID": @"e-1234-a8-b12" }
inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
NSSet *birthdays = [NSSet setWithObject:birthday];
expect(managedObjects).to.equal(birthdays);
}
@end