mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-12 17:43:34 +08:00
Added test case for NSMutableSet mapping on managed object. refs #1201
This commit is contained in:
@@ -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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -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;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
@dynamic createdAt;
|
||||
@dynamic updatedAt;
|
||||
@dynamic favoriteColors;
|
||||
@dynamic mutableFavoriteColors;
|
||||
|
||||
@dynamic favoriteCatID;
|
||||
@dynamic favoriteCat;
|
||||
|
||||
Reference in New Issue
Block a user