Skip to content

Commit

Permalink
Add test for an array being mapped to an NSOrderedSet.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Morton committed Jan 13, 2012
1 parent 8363d35 commit 3cf2ea5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Specs/ObjectMapping/RKObjectMappingOperationSpec.m
Expand Up @@ -27,12 +27,14 @@ @interface TestMappable : NSObject {
NSURL *_url;
NSString *_boolString;
NSDate *_date;
NSOrderedSet *_orderedSet;
}

@property (nonatomic, retain) NSURL *url;
@property (nonatomic, retain) NSString *boolString;
@property (nonatomic, retain) NSNumber *boolNumber;
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, retain) NSOrderedSet *orderedSet;

@end

Expand All @@ -42,6 +44,7 @@ @implementation TestMappable
@synthesize boolString = _boolString;
@synthesize boolNumber = _boolNumber;
@synthesize date = _date;
@synthesize orderedSet = _orderedSet;

- (BOOL)validateBoolString:(id *)ioValue error:(NSError **)outError {
if ([(NSObject *)*ioValue isKindOfClass:[NSString class]] && [(NSString *)*ioValue isEqualToString:@"FAIL"]) {
Expand Down Expand Up @@ -141,6 +144,22 @@ - (void)testShouldSuccessfullyMapNumbersToStrings {
[operation release];
}

- (void)testShouldSuccessfullyMapArraysToOrderedSets {
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
[mapping mapKeyPath:@"numbers" toAttribute:@"orderedSet"];
TestMappable* object = [[[TestMappable alloc] init] autorelease];

id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
id data = [parser objectFromString:@"{\"numbers\":[1, 2, 3]}" error:nil];

RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
BOOL success = [operation performMapping:nil];
assertThatBool(success, is(equalToBool(YES)));
NSOrderedSet *expectedSet = [NSOrderedSet orderedSetWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:2], [NSNumber numberWithInt:3], nil];
assertThat(object.orderedSet, is(equalTo(expectedSet)));
[operation release];
}

- (void)testShouldFailTheMappingOperationIfKeyValueValidationSetsAnError {
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
[mapping mapAttributes:@"boolString", nil];
Expand Down

0 comments on commit 3cf2ea5

Please sign in to comment.