Added test case for NSMutableSet mapping on managed object. refs #1201

This commit is contained in:
Blake Watters
2013-03-16 15:39:13 -04:00
parent a0a0adf7d1
commit 29f6e7cc08
5 changed files with 20 additions and 0 deletions

View File

@@ -587,4 +587,22 @@
expect(caughtException.reason).to.equal(@"`requestMapping` is not meant to be invoked on `RKEntityMapping`. You probably want to invoke `[RKObjectMapping requestMapping]`.");
}
- (void)testMappingArrayToMutableArray
{
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
RKObjectMapping *mapping = [RKEntityMapping mappingForEntityForName:@"Human" inManagedObjectStore:managedObjectStore];
[mapping addAttributeMappingsFromDictionary:@{ @"favoriteColors": @"mutableFavoriteColors" }];
NSDictionary *dictionary = @{ @"favoriteColors": @[ @"Blue", @"Red" ] };
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"Human" inManagedObjectContext:managedObjectStore.mainQueueManagedObjectContext];
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:human mapping:mapping];
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.mainQueueManagedObjectContext cache:nil];
operation.dataSource = dataSource;
NSError *error = nil;
[operation performMapping:&error];
assertThat(human.mutableFavoriteColors, is(equalTo(@[ @"Blue", @"Red" ])));
assertThat(human.mutableFavoriteColors, is(instanceOf([NSMutableArray class])));
}
@end

View File

@@ -33,6 +33,7 @@
@property (nonatomic, strong) NSDate *createdAt;
@property (nonatomic, strong) NSDate *updatedAt;
@property (nonatomic, strong) NSArray *favoriteColors;
@property (nonatomic, strong) NSMutableSet *mutableFavoriteColors;
@property (nonatomic, strong) NSSet *cats;
@property (nonatomic, strong) NSNumber *favoriteCatID;

View File

@@ -32,6 +32,7 @@
@dynamic createdAt;
@dynamic updatedAt;
@dynamic favoriteColors;
@dynamic mutableFavoriteColors;
@dynamic favoriteCatID;
@dynamic favoriteCat;