Respect rootKeyPath when returning empty dictionary in response to unmappable representation error

This commit is contained in:
Blake Watters
2012-10-05 21:48:19 -04:00
parent 0497c396d1
commit 224de85fb3
2 changed files with 16 additions and 3 deletions

View File

@@ -87,7 +87,7 @@
if (operation.error) {
if (operation.error.code == RKMappingErrorUnmappableRepresentation) {
// If the mapped object is empty, return an empty dictionary and no error
return @{};
return self.rootKeyPath ? @{ self.rootKeyPath: @{} } : @{};
}
if (error) *error = operation.error;

View File

@@ -186,8 +186,21 @@
NSError *error = nil;
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
expect(error).to.beNil();
expect(parameters).to.equal(@{});
EXP_expect(error).to.beNil();
EXP_expect(parameters).to.equal(@{});
}
- (void)testEmptyParameterizationRespectsRootKeyPath
{
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key12123" toKeyPath:@"key1-form-name"]];
NSError *error = nil;
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:@"root"];
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
EXP_expect(error).to.beNil();
EXP_expect(parameters).to.equal(@{@"root":@{}});
}
- (void)testShouldSerializeNestedObjectsContainingDatesToJSON