Fix incorrect serialization of a single object inputted as an array. closes #1289

This commit is contained in:
Blake Watters
2013-03-20 10:39:14 -04:00
parent 407b879a52
commit 24c0a25519
2 changed files with 32 additions and 8 deletions

View File

@@ -785,6 +785,28 @@
expect(array).to.equal(expected);
}
- (void)testPostingAnArrayWithSingleObjectGeneratesAnArray
{
RKObjectMapping *firstRequestMapping = [RKObjectMapping requestMapping];
[firstRequestMapping addAttributeMappingsFromArray:@[ @"name", @"emailAddress" ]];
RKRequestDescriptor *firstRequestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:firstRequestMapping objectClass:[RKTestUser class] rootKeyPath:@"whatever"];
RKTestUser *user = [RKTestUser new];
user.name = @"Blake";
user.emailAddress = @"blake@restkit.org";
RKObjectManager *objectManager = [RKTestFactory objectManager];
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;
[objectManager addRequestDescriptor:firstRequestDescriptor];
NSArray *arrayOfObjects = @[ user ];
NSURLRequest *request = [objectManager requestWithObject:arrayOfObjects method:RKRequestMethodPOST path:@"/path" parameters:nil];
NSArray *array = [NSJSONSerialization JSONObjectWithData:request.HTTPBody options:0 error:nil];
NSDictionary *expected = @{ @"whatever": @[ @{ @"name": @"Blake", @"emailAddress": @"blake@restkit.org" } ] };
expect(array).to.equal(expected);
}
- (void)testPostingNilObjectWithExtraParameters
{
RKObjectMapping *firstRequestMapping = [RKObjectMapping requestMapping];