Permalink
Browse files

Pushing code up for Jeremy

  • Loading branch information...
1 parent dbd752e commit 3dd73611161318e8273804c23ed2249e0dd8cbdf @blakewatters blakewatters committed Jun 16, 2011
View
16 Code/Support/Parsers/XML/RKXMLParserLibXML.m
@@ -61,7 +61,21 @@ - (id)parseNode:(xmlNode*)node {
// 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;
}
View
2 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);
View
2 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.
View
14 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 = "<group>"; };
2590E85D1252515400531FA8 /* GTMBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMBase64.h; sourceTree = "<group>"; };
2590E85E1252515400531FA8 /* GTMBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMBase64.m; sourceTree = "<group>"; };
+ 25915ACF13A2E82200EA63B0 /* tab_data.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = tab_data.xml; sourceTree = "<group>"; };
25952DE8136C8F3500D04F93 /* RKObjectMappingOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKObjectMappingOperation.h; sourceTree = "<group>"; };
25952DE9136C8F3500D04F93 /* RKObjectMappingOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectMappingOperation.m; sourceTree = "<group>"; };
25952DEF136C8F9C00D04F93 /* RKObjectMappingOperationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectMappingOperationSpec.m; sourceTree = "<group>"; };
@@ -1225,11 +1227,20 @@
path = GTM;
sourceTree = "<group>";
};
+ 25915ACE13A2E82200EA63B0 /* XML */ = {
+ isa = PBXGroup;
+ children = (
+ 25915ACF13A2E82200EA63B0 /* tab_data.xml */,
+ );
+ path = XML;
+ sourceTree = "<group>";
+ };
25952ED6136F563E00D04F93 /* Fixtures */ = {
isa = PBXGroup;
children = (
- 25952ED7136F563E00D04F93 /* Assets */,
25952ED9136F563E00D04F93 /* JSON */,
+ 25915ACE13A2E82200EA63B0 /* XML */,
+ 25952ED7136F563E00D04F93 /* Assets */,
);
path = Fixtures;
sourceTree = "<group>";
@@ -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;
};
View
121 Specs/ObjectMapping/RKObjectMappingNextGenSpec.m
@@ -125,6 +125,24 @@ - (BOOL)isEqual:(id)object {
@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 @@ - (void)itShouldPerformBasicMapping {
[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 @@ - (void)itShouldMapACollectionOfSimpleObjectDictionaries {
[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 @@ - (void)itShouldDetermineTheObjectMappingByConsultingTheMappingProviderWhenThere
[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 @@ - (void)itShouldAddAnErrorWhenTheKeyPathMappingAndObjectClassDoNotAgree {
[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 @@ - (void)itShouldMapToATargetObject {
[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 @@ - (void)itShouldCreateANewInstanceOfTheAppropriateDestinationObjectWhenThereIsNo
[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 @@ - (void)itShouldDetermineTheMappingClassForAKeyPathByConsultingTheMappingProvide
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 @@ - (void)itShouldMapWithoutATargetMapping {
[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 @@ - (void)itShouldMapACollectionOfObjects {
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 @@ - (void)itShouldMapRegisteredSubKeyPathsOfAnUnmappableDictionaryAndReturnTheResu
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 @@ - (void)itShouldAddAnErrorWhenYouTryToMapAnArrayToATargetObject {
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)itShouldAddAnErrorWhenYouTryToMapAnArrayToATargetObject {
}
- (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)itShouldAddAnErrorWhenAttemptingToMapADictionaryWithoutAnObjectMapping {
- (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 @@ - (void)itShouldInformTheDelegateWhenMappingBegins {
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 @@ - (void)itShouldInformTheDelegateWhenMappingEnds {
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 @@ - (void)itShouldInformTheDelegateWhenCheckingForObjectMappingForKeyPathIsSuccess
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 @@ - (void)itShouldInformTheDelegateWhenCheckingForObjectMappingForKeyPathIsNotSucc
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 @@ - (void)itShouldInformTheDelegateOfError {
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 @@ - (void)itShouldNotifyTheDelegateWhenItWillMapAnObject {
[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 @@ - (void)itShouldNotifyTheDelegateWhenItDidMapAnObject {
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 @@ - (void)itShouldNotifyTheDelegateWhenItFailedToMapAnObject {
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 @@ - (void)itShouldMapAStringToADateAttribute {
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 @@ - (void)itShouldMapStringToURL {
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 @@ - (void)itShouldMapAStringToANumberBool {
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 @@ - (void)itShouldMapAShortTrueStringToANumberBool {
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 @@ - (void)itShouldMapAShortFalseStringToANumberBool {
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 @@ - (void)itShouldMapAStringToANumber {
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 @@ - (void)itShouldMapAStringToADecimalNumber {
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 @@ - (void)itShouldMapANumberToAString {
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 @@ - (void)itShouldMapANestedKeyPathToAnAttribute {
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 @@ - (void)itShouldMapANestedArrayOfStringsToAnAttribute {
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 @@ - (void)itShouldMapANestedDictionaryToAnAttribute {
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 @@ - (void)itShouldNotSetAPropertyWhenTheValueIsTheSame {
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 @@ - (void)itShouldNotSetTheDestinationPropertyWhenBothAreNil {
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 @@ - (void)itShouldSetNilForNSNullValues {
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 @@ - (void)itShouldOptionallySetNilForAMissingKeyPath {
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 @@ - (void)itShouldOptionallyIgnoreAMissingSourceKeyPath {
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 @@ - (void)itShouldMapANestedObject {
[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 @@ - (void)itShouldMapANestedObjectCollection {
[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 @@ - (void)itShouldMapANestedArrayIntoASet {
[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 @@ - (void)itShouldNotSetThePropertyWhenTheNestedObjectIsIdentical {
[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 @@ - (void)itShouldNotSetThePropertyWhenTheNestedObjectCollectionIsIdentical {
[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 @@ - (void)itShouldOptionallyNilOutTheRelationshipIfItIsMissing {
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 @@ - (void)itShouldNotNilOutTheRelationshipIfItIsMissingAndCurrentlyNilOnTheTargetO
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 @@ - (void)itShouldRegisterRailsIdiomaticObjects {
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
View
2 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 <UISpec>
View
23 Specs/Runner/RKSpecEnvironment.m
@@ -75,20 +75,31 @@ void RKSpecStubNetworkAvailability(BOOL isNetworkAvailable) {
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<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON];
- id object = [parser objectFromString:JSON error:&error];
+ NSString* data = RKSpecReadFixture(fileName);
+ NSString* MIMEType = RKSpecMIMETypeForFixture(fileName);
+ id<RKParser> 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 {
2 Specs/Runner/UISpec
@@ -1 +1 @@
-Subproject commit 5b0c81f99d90ebd052bef6385abf62ea2e4c041a
+Subproject commit 9ccf113a21c04b11f7e37a91a87d1a58e7ef3e55

0 comments on commit 3dd7361

Please sign in to comment.