Skip to content

Commit

Permalink
[#23] remove number support
Browse files Browse the repository at this point in the history
  • Loading branch information
jjburka committed Feb 19, 2009
1 parent aa08beb commit 7164876
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions Classes/lib/Serialization/XML/FromXMLElementDelegate.m
Expand Up @@ -100,12 +100,16 @@ - (id) convertProperty:(NSString *)propertyValue toType:(NSString *)type {
else if ([type isEqualToString:@"date"]) {
return [NSDate fromXMLDateString:propertyValue];
}
else if ([type isEqualToString:@"decimal"]) {
return [NSDecimalNumber decimalNumberWithString:propertyValue];
}
else if ([type isEqualToString:@"integer"]) {
return [NSNumber numberWithInt:[propertyValue intValue]];
}

// uncomment this if you what to support NSNumber and NSDecimalNumber
// if you do your classId must be a NSNumber since rails will pass it as such
//else if ([type isEqualToString:@"decimal"]) {
// return [NSDecimalNumber decimalNumberWithString:propertyValue];
//}
//else if ([type isEqualToString:@"integer"]) {
// return [NSNumber numberWithInt:[propertyValue intValue]];
//}

else {
return [NSString fromXmlString:propertyValue];
}
Expand Down
4 changes: 3 additions & 1 deletion Classes/unit_tests/XMLDeserializeTest.m
Expand Up @@ -33,9 +33,11 @@ -(void) testDeserializationOfModel {
STAssertTrue([testClass.name isEqualToString:@"Hourly Test"] , @"should be \"Hourly Test\"");
STAssertTrue([testClass.createdAt isEqualToDate:dateToTest] , @"Date should be 2009-02-16T10:43:50Z , but got %@" , testClass.createdAt);
STAssertTrue([testClass.testClassId intValue] == 1,@"Model should have an id of 1");

NSString *output = @"<test-class><created-at type=\"datetime\">2009-02-16T10:43:50Z</created-at><weight>2.1</weight><name>Hourly Test</name><id>1</id></test-class>";
STAssertEqualStrings([testClass toXMLElementAs:@"test-class" excludingInArray:[NSArray array]
withTranslations:[NSDictionary dictionaryWithObject:@"id" forKey:@"testClassId"]],
testXML, @"reserialization of object should match original string");
output, @"reserialization of object should match original string");
}

-(void) testDeserializationOfArray {
Expand Down

0 comments on commit 7164876

Please sign in to comment.