Files
RestKit/Tests/Logic/CoreData/RKFetchRequestMappingCacheTest.m
Blake Watters 8dc54a89b2 Major overhaul to the Core Data managed object identification and relationship connection support.
* Replaces primary key with `RKEntityIdentifier`
* Add support for use of compound keys for object identification
* Refactor `RKConnectionMapping` to `RKConnectionDescription` and add support for connecting with multiple attributes
* Clarify naming of representation key methods to better match naming conventions
* Add type transformation support for object identification
* Greatly expand test coverage for object identification
* Drop the `NSEntityDescription` category
* Simplify the `RKManagedObjectCaching` protocol
* Add compound key support to the Fetch Request and In Memory Cache implementations
* Replace Kiwi with Specta for tests where contexts are helpful for organization
* Rename `defaultValueForMissingAttribute` to `defaultValueForAttribute`
2012-11-27 10:29:36 -05:00

61 lines
3.0 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.entityIdentifier = [RKEntityIdentifier identifierWithEntityName:@"Cat" attributes:@[ @"railsID" ] inManagedObjectStore:managedObjectStore];
RKCat *reginald = [NSEntityDescription insertNewObjectForEntityForName:@"Cat" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
reginald.name = @"Reginald";
reginald.railsID = [NSNumber numberWithInt:123456];
[managedObjectStore.persistentStoreManagedObjectContext save:nil];
NSArray *managedObjects = [cache managedObjectsWithEntity:entity
attributeValues:@{ @"railsID": @123456 }
inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
NSArray *cats = @[ 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.entityIdentifier = [RKEntityIdentifier identifierWithEntityName:@"Event" attributes:@[ @"eventID" ] inManagedObjectStore:managedObjectStore];
RKEvent *birthday = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
birthday.eventID = @"e-1234-a8-b12";
[managedObjectStore.persistentStoreManagedObjectContext save:nil];
NSArray *managedObjects = [cache managedObjectsWithEntity:entity
attributeValues:@{ @"eventID": @"e-1234-a8-b12" }
inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
NSArray *birthdays = @[ birthday ];
expect(managedObjects).to.equal(birthdays);
}
@end