Files
RestKit/Tests/Logic/CoreData/RKFetchRequestMappingCacheTest.m
Blake Watters f0706dbdbf Work in progress
Conflicts:
	Code/CoreData/RKManagedObjectLoader.h
	Code/CoreData/RKManagedObjectLoader.m
	Code/CoreData/RKManagedObjectMapping.m
	Code/CoreData/RKManagedObjectMappingOperation.m
	Code/CoreData/RKManagedObjectStore.m
	Code/CoreData/RKManagedObjectThreadSafeInvocation.h
	Code/CoreData/RKManagedObjectThreadSafeInvocation.m
	Code/CoreData/RKSearchableManagedObject.m
	Code/ObjectMapping/RKObjectLoader.m
	Code/ObjectMapping/RKObjectMapper.h
	Code/ObjectMapping/RKObjectMappingOperation.m
	RestKit.xcodeproj/project.pbxproj
	Tests/Logic/CoreData/RKManagedObjectThreadSafeInvocationTest.m
2012-07-13 13:07:42 -04:00

61 lines
2.6 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 *objectStore = [RKTestFactory managedObjectStore];
RKFetchRequestManagedObjectCache *cache = [RKFetchRequestManagedObjectCache new];
NSEntityDescription *entity = [RKCat entityDescription];
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityWithName:@"RKCat" inManagedObjectContext:objectStore.primaryManagedObjectContext];
mapping.primaryKeyAttribute = @"railsID";
RKCat *reginald = [RKCat createInContext:objectStore.primaryManagedObjectContext];
reginald.name = @"Reginald";
reginald.railsID = [NSNumber numberWithInt:123456];
[objectStore.primaryManagedObjectContext save:nil];
NSManagedObject *cachedObject = [cache findInstanceOfEntity:entity
withPrimaryKeyAttribute:mapping.primaryKeyAttribute
value:[NSNumber numberWithInt:123456]
inManagedObjectContext:objectStore.primaryManagedObjectContext];
assertThat(cachedObject, is(equalTo(reginald)));
}
- (void)testFetchRequestMappingCacheReturnsObjectsWithStringPrimaryKey
{
// RKEvent entity. String primary key
RKManagedObjectStore *objectStore = [RKTestFactory managedObjectStore];
RKFetchRequestManagedObjectCache *cache = [RKFetchRequestManagedObjectCache new];
NSEntityDescription *entity = [RKEvent entityDescription];
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityWithName:@"RKEvent" inManagedObjectContext:objectStore.primaryManagedObjectContext];
mapping.primaryKeyAttribute = @"eventID";
RKEvent *birthday = [RKEvent createInContext:objectStore.primaryManagedObjectContext];
birthday.eventID = @"e-1234-a8-b12";
[objectStore.primaryManagedObjectContext save:nil];
NSManagedObject *cachedObject = [cache findInstanceOfEntity:entity
withPrimaryKeyAttribute:mapping.primaryKeyAttribute
value:@"e-1234-a8-b12"
inManagedObjectContext:objectStore.primaryManagedObjectContext];
assertThat(cachedObject, is(equalTo(birthday)));
}
@end