diff --git a/Code/Support/Parsers/XML/RKXMLParserLibXML.m b/Code/Support/Parsers/XML/RKXMLParserLibXML.m index ba271318..1e6d31ec 100644 --- a/Code/Support/Parsers/XML/RKXMLParserLibXML.m +++ b/Code/Support/Parsers/XML/RKXMLParserLibXML.m @@ -61,7 +61,21 @@ // We have both attributes and children. merge everything together. NSMutableDictionary* results = [NSMutableDictionary dictionary]; for (NSDictionary* dict in nodes) { - [results addEntriesFromDictionary:dict]; + for (NSString* key in dict) { + if ([results valueForKey:key]) { + // If we have overlapping keys, assemble them into an array + id currentValue = [results valueForKey:key]; + if ([currentValue isKindOfClass:[NSMutableArray class]]) { + [(NSMutableArray*)currentValue addObject:[dict valueForKey:key]]; + } else { + NSMutableArray* array = [NSMutableArray arrayWithObject:currentValue]; + [results setValue:array forKey:key]; + } + } else { + [results setValue:[dict allValues] forKey:key]; + } + } +// [results addEntriesFromDictionary:dict]; } return results; } diff --git a/Code/Support/RKLog.h b/Code/Support/RKLog.h index 41391904..ae9bf2a1 100644 --- a/Code/Support/RKLog.h +++ b/Code/Support/RKLog.h @@ -89,7 +89,7 @@ lcl_log(RKLogComponent, lcl_vTrace, @"" __VA_ARGS__); RKLogConfigureByName("RestKit/Network", RKLogLevelDebug); // Log only critical messages from the Object Mapping component - RKLogConfigureByName("RestKit/Object Mapping", RKLogLevelCritical); + RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelCritical); */ #define RKLogConfigureByName(name, level) \ lcl_configure_by_name(name, level); diff --git a/LICENSE b/LICENSE index d6456956..a91a0381 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2009 Two Toasters Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/RestKit.xcodeproj/project.pbxproj b/RestKit.xcodeproj/project.pbxproj index bbcf4c35..e5d88dba 100644 --- a/RestKit.xcodeproj/project.pbxproj +++ b/RestKit.xcodeproj/project.pbxproj @@ -160,6 +160,7 @@ 2590E8601252515400531FA8 /* GHNSBundle+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 2590E85B1252515400531FA8 /* GHNSBundle+Utils.m */; }; 2590E8611252515400531FA8 /* GTMBase64.h in Headers */ = {isa = PBXBuildFile; fileRef = 2590E85D1252515400531FA8 /* GTMBase64.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2590E8621252515400531FA8 /* GTMBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 2590E85E1252515400531FA8 /* GTMBase64.m */; }; + 25915AD013A2E82200EA63B0 /* tab_data.xml in Resources */ = {isa = PBXBuildFile; fileRef = 25915ACF13A2E82200EA63B0 /* tab_data.xml */; }; 25952DEA136C8F3500D04F93 /* RKObjectMappingOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 25952DE8136C8F3500D04F93 /* RKObjectMappingOperation.h */; settings = {ATTRIBUTES = (Public, ); }; }; 25952DEB136C8F3500D04F93 /* RKObjectMappingOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 25952DE9136C8F3500D04F93 /* RKObjectMappingOperation.m */; }; 25952DF5136C8FD500D04F93 /* RKObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 25952DF3136C8FD500D04F93 /* RKObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -532,6 +533,7 @@ 2590E85B1252515400531FA8 /* GHNSBundle+Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GHNSBundle+Utils.m"; sourceTree = ""; }; 2590E85D1252515400531FA8 /* GTMBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMBase64.h; sourceTree = ""; }; 2590E85E1252515400531FA8 /* GTMBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMBase64.m; sourceTree = ""; }; + 25915ACF13A2E82200EA63B0 /* tab_data.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = tab_data.xml; sourceTree = ""; }; 25952DE8136C8F3500D04F93 /* RKObjectMappingOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKObjectMappingOperation.h; sourceTree = ""; }; 25952DE9136C8F3500D04F93 /* RKObjectMappingOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectMappingOperation.m; sourceTree = ""; }; 25952DEF136C8F9C00D04F93 /* RKObjectMappingOperationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectMappingOperationSpec.m; sourceTree = ""; }; @@ -1225,11 +1227,20 @@ path = GTM; sourceTree = ""; }; + 25915ACE13A2E82200EA63B0 /* XML */ = { + isa = PBXGroup; + children = ( + 25915ACF13A2E82200EA63B0 /* tab_data.xml */, + ); + path = XML; + sourceTree = ""; + }; 25952ED6136F563E00D04F93 /* Fixtures */ = { isa = PBXGroup; children = ( - 25952ED7136F563E00D04F93 /* Assets */, 25952ED9136F563E00D04F93 /* JSON */, + 25915ACE13A2E82200EA63B0 /* XML */, + 25952ED7136F563E00D04F93 /* Assets */, ); path = Fixtures; sourceTree = ""; @@ -1823,6 +1834,7 @@ 25952F0F136F8F7700D04F93 /* users.json in Resources */, 25952FDD1370959900D04F93 /* LICENSE.txt in Resources */, 25952FDF1370959900D04F93 /* README.markdown in Resources */, + 25915AD013A2E82200EA63B0 /* tab_data.xml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m b/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m index 11012f87..c5bde832 100644 --- a/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m +++ b/Specs/ObjectMapping/RKObjectMappingNextGenSpec.m @@ -125,6 +125,24 @@ @end +// See Specs/Fixtures/XML/tab_data.xml +@interface RKSpecTabData : NSObject { + NSString* _title; + NSString* _summary; +} + +@property (nonatomic, retain) NSString* title; +@property (nonatomic, retain) NSString* summary; + +@end + +@implementation RKSpecTabData + +@synthesize title = _title; +@synthesize summary = _summary; + +@end + //////////////////////////////////////////////////////////////////////////////// #pragma mark - @@ -243,7 +261,7 @@ [mapping addAttributeMapping:nameMapping]; RKObjectMapper* mapper = [RKObjectMapper new]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; BOOL success = [mapper mapFromObject:userInfo toObject:user atKeyPath:@"" usingMapping:mapping]; [mapper release]; @@ -260,7 +278,7 @@ [mapping addAttributeMapping:nameMapping]; RKObjectMapper* mapper = [RKObjectMapper new]; - id userInfo = RKSpecParseFixtureJSON(@"users.json"); + id userInfo = RKSpecParseFixture(@"users.json"); NSArray* users = [mapper mapCollection:userInfo atKeyPath:@"" usingMapping:mapping]; [expectThat([users count]) should:be(3)]; RKExampleUser* blake = [users objectAtIndex:0]; @@ -274,7 +292,7 @@ [provider setMapping:mapping forKeyPath:@""]; id mockProvider = [OCMockObject partialMockForObject:provider]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:mockProvider]; mapper.targetObject = [RKExampleUser user]; [mapper performMapping]; @@ -288,7 +306,7 @@ [provider setMapping:mapping forKeyPath:@""]; id mockProvider = [OCMockObject partialMockForObject:provider]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:mockProvider]; mapper.targetObject = [NSDictionary new]; [mapper performMapping]; @@ -306,7 +324,7 @@ [provider setMapping:mapping forKeyPath:@""]; id mockProvider = [OCMockObject partialMockForObject:provider]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:mockProvider]; RKExampleUser* user = [RKExampleUser user]; mapper.targetObject = user; @@ -327,7 +345,7 @@ [provider setMapping:mapping forKeyPath:@""]; id mockProvider = [OCMockObject partialMockForObject:provider]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:mockProvider]; id mappingResult = [[mapper performMapping] asObject]; [expectThat([mappingResult isKindOfClass:[RKExampleUser class]]) should:be(YES)]; @@ -340,7 +358,7 @@ id mockProvider = [OCMockObject partialMockForObject:provider]; [[mockProvider expect] objectMappingsByKeyPath]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:mockProvider]; [mapper performMapping]; [mockProvider verify]; @@ -357,7 +375,7 @@ [provider setMapping:mapping forKeyPath:@""]; id mockProvider = [OCMockObject partialMockForObject:provider]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:mockProvider]; RKExampleUser* user = [[mapper performMapping] asObject]; [expectThat([user isKindOfClass:[RKExampleUser class]]) should:be(YES)]; @@ -373,7 +391,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@""]; - id userInfo = RKSpecParseFixtureJSON(@"users.json"); + id userInfo = RKSpecParseFixture(@"users.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; RKObjectMappingResult* result = [mapper performMapping]; NSArray* users = [result asCollection]; @@ -414,7 +432,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@"user"]; - id userInfo = RKSpecParseFixtureJSON(@"nested_user.json"); + id userInfo = RKSpecParseFixture(@"nested_user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; NSDictionary* dictionary = [[mapper performMapping] asDictionary]; [expectThat([dictionary isKindOfClass:[NSDictionary class]]) should:be(YES)]; @@ -434,7 +452,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@""]; - id userInfo = RKSpecParseFixtureJSON(@"users.json"); + id userInfo = RKSpecParseFixture(@"users.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; mapper.targetObject = [RKExampleUser user]; [mapper performMapping]; @@ -443,7 +461,7 @@ } - (void)itShouldAddAnErrorWhenAttemptingToMapADictionaryWithoutAnObjectMapping { - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [mapper performMapping]; @@ -453,7 +471,7 @@ - (void)itShouldAddAnErrorWhenAttemptingToMapACollectionWithoutAnObjectMapping { RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; - id userInfo = RKSpecParseFixtureJSON(@"users.json"); + id userInfo = RKSpecParseFixture(@"users.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [mapper performMapping]; [expectThat([mapper errorCount]) should:be(1)]; @@ -468,7 +486,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@""]; - id userInfo = RKSpecParseFixtureJSON(@"users.json"); + id userInfo = RKSpecParseFixture(@"users.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [[mockDelegate expect] objectMapperWillBeginMapping:mapper]; mapper.delegate = mockDelegate; @@ -482,7 +500,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@""]; - id userInfo = RKSpecParseFixtureJSON(@"users.json"); + id userInfo = RKSpecParseFixture(@"users.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [[mockDelegate stub] objectMapperWillBeginMapping:mapper]; [[mockDelegate expect] objectMapperDidFinishMapping:mapper]; @@ -497,7 +515,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@""]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [[mockDelegate expect] objectMapper:mapper didFindMappableObject:[OCMArg any] atKeyPath:@""withMapping:mapping]; mapper.delegate = mockDelegate; @@ -510,7 +528,7 @@ RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[RKExampleUser class]]; [provider setMapping:mapping forKeyPath:@"users"]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(RKObjectMapperDelegate)]; [[mockDelegate expect] objectMapper:mapper didNotFindMappableObjectAtKeyPath:@"users"]; @@ -523,7 +541,7 @@ id mockProvider = [OCMockObject niceMockForClass:[RKObjectMappingProvider class]]; id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(RKObjectMapperDelegate)]; - id userInfo = RKSpecParseFixtureJSON(@"users.json"); + id userInfo = RKSpecParseFixture(@"users.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:mockProvider]; [[mockDelegate expect] objectMapper:mapper didAddError:[OCMArg isNotNil]]; mapper.delegate = mockDelegate; @@ -537,7 +555,7 @@ [provider setMapping:mapping forKeyPath:@""]; id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(RKObjectMapperDelegate)]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [[mockDelegate expect] objectMapper:mapper willMapFromObject:userInfo toObject:[OCMArg any] atKeyPath:@"" usingMapping:mapping]; mapper.delegate = mockDelegate; @@ -553,7 +571,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@""]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [[mockDelegate expect] objectMapper:mapper didMapFromObject:userInfo toObject:[OCMArg any] atKeyPath:@"" usingMapping:mapping]; mapper.delegate = mockDelegate; @@ -567,7 +585,7 @@ RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease]; [provider setMapping:mapping forKeyPath:@""]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider]; [[mockDelegate expect] objectMapper:mapper didFailMappingFromObject:userInfo toObject:[OCMArg any] withError:[OCMArg any] atKeyPath:@"" usingMapping:mapping]; mapper.delegate = mockDelegate; @@ -692,7 +710,7 @@ RKObjectAttributeMapping* birthDateMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"birthdate" toKeyPath:@"birthDate"]; [mapping addAttributeMapping:birthDateMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -708,7 +726,7 @@ RKObjectAttributeMapping* websiteMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"website" toKeyPath:@"website"]; [mapping addAttributeMapping:websiteMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -724,7 +742,7 @@ RKObjectAttributeMapping* websiteMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"is_developer" toKeyPath:@"isDeveloper"]; [mapping addAttributeMapping:websiteMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -738,7 +756,7 @@ RKObjectAttributeMapping* websiteMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"is_developer" toKeyPath:@"isDeveloper"]; [mapping addAttributeMapping:websiteMapping]; - NSDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; RKExampleUser* user = [RKExampleUser user]; [dictionary setValue:@"T" forKey:@"is_developer"]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; @@ -753,7 +771,7 @@ RKObjectAttributeMapping* websiteMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"is_developer" toKeyPath:@"isDeveloper"]; [mapping addAttributeMapping:websiteMapping]; - NSDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; RKExampleUser* user = [RKExampleUser user]; [dictionary setValue:@"f" forKey:@"is_developer"]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; @@ -798,7 +816,7 @@ RKObjectAttributeMapping* websiteMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"lucky_number" toKeyPath:@"luckyNumber"]; [mapping addAttributeMapping:websiteMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -812,7 +830,7 @@ RKObjectAttributeMapping* websiteMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"weight" toKeyPath:@"weight"]; [mapping addAttributeMapping:websiteMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -829,7 +847,7 @@ RKObjectAttributeMapping* websiteMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"lucky_number" toKeyPath:@"name"]; [mapping addAttributeMapping:websiteMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -843,7 +861,7 @@ RKObjectAttributeMapping* countryMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"address.country" toKeyPath:@"country"]; [mapping addAttributeMapping:countryMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -857,7 +875,7 @@ RKObjectAttributeMapping* countryMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"interests" toKeyPath:@"interests"]; [mapping addAttributeMapping:countryMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -872,7 +890,7 @@ RKObjectAttributeMapping* countryMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"address" toKeyPath:@"addressDictionary"]; [mapping addAttributeMapping:countryMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:dictionary destinationObject:user objectMapping:mapping]; NSError* error = nil; @@ -891,7 +909,7 @@ RKObjectAttributeMapping* nameMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]; [mapping addAttributeMapping:nameMapping]; - NSDictionary* dictionary = RKSpecParseFixtureJSON(@"user.json"); + NSDictionary* dictionary = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; user.name = @"Blake Watters"; id mockUser = [OCMockObject partialMockForObject:user]; @@ -906,7 +924,7 @@ RKObjectAttributeMapping* nameMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]; [mapping addAttributeMapping:nameMapping]; - NSMutableDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSMutableDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; [dictionary setValue:[NSNull null] forKey:@"name"]; RKExampleUser* user = [RKExampleUser user]; user.name = nil; @@ -922,7 +940,7 @@ RKObjectAttributeMapping* nameMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]; [mapping addAttributeMapping:nameMapping]; - NSDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; [dictionary setValue:[NSNull null] forKey:@"name"]; RKExampleUser* user = [RKExampleUser user]; user.name = @"Blake Watters"; @@ -939,7 +957,7 @@ RKObjectAttributeMapping* nameMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]; [mapping addAttributeMapping:nameMapping]; - NSMutableDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSMutableDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; [dictionary removeObjectForKey:@"name"]; RKExampleUser* user = [RKExampleUser user]; user.name = @"Blake Watters"; @@ -959,7 +977,7 @@ RKObjectAttributeMapping* nameMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]; [mapping addAttributeMapping:nameMapping]; - NSMutableDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSMutableDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; [dictionary removeObjectForKey:@"name"]; RKExampleUser* user = [RKExampleUser user]; user.name = @"Blake Watters"; @@ -988,7 +1006,7 @@ [userMapping addRelationshipMapping:hasOneMapping]; RKObjectMapper* mapper = [RKObjectMapper new]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; BOOL success = [mapper mapFromObject:userInfo toObject:user atKeyPath:@"" usingMapping:userMapping]; [mapper release]; @@ -1006,7 +1024,7 @@ [userMapping addRelationshipMapping:hasManyMapping]; RKObjectMapper* mapper = [RKObjectMapper new]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; BOOL success = [mapper mapFromObject:userInfo toObject:user atKeyPath:@"" usingMapping:userMapping]; [mapper release]; @@ -1027,7 +1045,7 @@ [userMapping addRelationshipMapping:hasManyMapping]; RKObjectMapper* mapper = [RKObjectMapper new]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; BOOL success = [mapper mapFromObject:userInfo toObject:user atKeyPath:@"" usingMapping:userMapping]; [mapper release]; @@ -1059,7 +1077,7 @@ [userMapping addRelationshipMapping:hasOneMapping]; RKObjectMapper* mapper = [RKObjectMapper new]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); [mapper mapFromObject:userInfo toObject:user atKeyPath:@"" usingMapping:userMapping]; [mapper release]; } @@ -1075,7 +1093,7 @@ [userMapping addRelationshipMapping:hasManyMapping]; RKObjectMapper* mapper = [RKObjectMapper new]; - id userInfo = RKSpecParseFixtureJSON(@"user.json"); + id userInfo = RKSpecParseFixture(@"user.json"); RKExampleUser* user = [RKExampleUser user]; // Set the friends up @@ -1111,7 +1129,7 @@ RKObjectRelationshipMapping* relationshipMapping = [RKObjectRelationshipMapping mappingFromKeyPath:@"address" toKeyPath:@"address" objectMapping:addressMapping]; [userMapping addRelationshipMapping:relationshipMapping]; - NSMutableDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSMutableDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; [dictionary removeObjectForKey:@"address"]; id mockMapping = [OCMockObject partialMockForObject:userMapping]; BOOL returnValue = YES; @@ -1138,7 +1156,7 @@ RKObjectRelationshipMapping* relationshipMapping = [RKObjectRelationshipMapping mappingFromKeyPath:@"address" toKeyPath:@"address" objectMapping:addressMapping]; [userMapping addRelationshipMapping:relationshipMapping]; - NSMutableDictionary* dictionary = [RKSpecParseFixtureJSON(@"user.json") mutableCopy]; + NSMutableDictionary* dictionary = [RKSpecParseFixture(@"user.json") mutableCopy]; [dictionary removeObjectForKey:@"address"]; id mockMapping = [OCMockObject partialMockForObject:userMapping]; BOOL returnValue = YES; @@ -1180,4 +1198,19 @@ assertThat(user.website, is(equalTo([NSURL URLWithString:@"http://restkit.org/"]))); } +#pragma mark - XML + +- (void)itShouldMapXML { + RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[RKSpecTabData class]]; + [mapping mapAttributes:@"title", @"summary", nil]; + RKObjectMappingProvider* provider = [[RKObjectMappingProvider alloc] init]; + id data = RKSpecParseFixture(@"tab_data.xml"); + NSLog(@"%@", data); + assertThat([data valueForKeyPath:@"tabdata.item"], is(instanceOf([NSArray class]))); + [provider setMapping:mapping forKeyPath:@"tabdata.item"]; + RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:data mappingProvider:provider]; + RKObjectMappingResult* result = [mapper performMapping]; + assertThatInt([[result asCollection] count], is(equalToInt(2))); +} + @end diff --git a/Specs/Runner/RKSpecEnvironment.h b/Specs/Runner/RKSpecEnvironment.h index 0fede8fa..c4c1ad6b 100644 --- a/Specs/Runner/RKSpecEnvironment.h +++ b/Specs/Runner/RKSpecEnvironment.h @@ -42,7 +42,7 @@ RKManagedObjectStore* RKSpecNewManagedObjectStore(); // Read the contents of a fixture file from the app bundle NSString* RKSpecReadFixture(NSString* fileName); -id RKSpecParseFixtureJSON(NSString* fileName); +id RKSpecParseFixture(NSString* fileName); // Base class for specs. Allows UISpec to run the specs and use of Hamcrest matchers... @interface RKSpec : NSObject diff --git a/Specs/Runner/RKSpecEnvironment.m b/Specs/Runner/RKSpecEnvironment.m index b8a90bae..e9f4896f 100644 --- a/Specs/Runner/RKSpecEnvironment.m +++ b/Specs/Runner/RKSpecEnvironment.m @@ -75,20 +75,31 @@ NSString* RKSpecReadFixture(NSString* fileName) { return fixtureData; } -id RKSpecParseFixtureJSON(NSString* fileName) { +NSString* RKSpecMIMETypeForFixture(NSString* fileName) { + NSString* extension = [[fileName pathExtension] lowercaseString]; + if ([extension isEqualToString:@"xml"]) { + return RKMIMETypeXML; + } else if ([extension isEqualToString:@"json"]) { + return RKMIMETypeJSON; + } else { + return nil; + } +} + +id RKSpecParseFixture(NSString* fileName) { NSError* error = nil; - NSString* JSON = RKSpecReadFixture(fileName); - id parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON]; - id object = [parser objectFromString:JSON error:&error]; + NSString* data = RKSpecReadFixture(fileName); + NSString* MIMEType = RKSpecMIMETypeForFixture(fileName); + id parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:MIMEType]; + id object = [parser objectFromString:data error:&error]; if (object == nil) { - NSLog(@"ERROR: Failed to parse JSON fixture '%@'. Error: %@", fileName, [error localizedDescription]); + RKLogCritical(@"Failed to parse JSON fixture '%@'. Error: %@", fileName, [error localizedDescription]); return nil; } return object; } - @implementation RKSpec - (void)failWithException:(NSException *) e { diff --git a/Specs/Runner/UISpec b/Specs/Runner/UISpec index 5b0c81f9..9ccf113a 160000 --- a/Specs/Runner/UISpec +++ b/Specs/Runner/UISpec @@ -1 +1 @@ -Subproject commit 5b0c81f99d90ebd052bef6385abf62ea2e4c041a +Subproject commit 9ccf113a21c04b11f7e37a91a87d1a58e7ef3e55