Add test case for empty 5xx response. refs #1169

This commit is contained in:
Blake Watters
2013-01-18 17:51:56 -05:00
parent a75edcea2e
commit 3d52c459aa
2 changed files with 22 additions and 0 deletions

View File

@@ -650,4 +650,21 @@
expect([requestOperation.error localizedDescription]).to.equal(@"error1, error2");
}
- (void)testFiveHundredErrorWithEmptyResponse
{
RKObjectMapping *errorResponseMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
[errorResponseMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"errorMessage"]];
RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorResponseMapping pathPattern:nil keyPath:@"errors" statusCodes:nil];
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
RKResponseDescriptor *userDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:userMapping pathPattern:nil keyPath:@"user" statusCodes:[NSIndexSet indexSetWithIndex:200]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/500" relativeToURL:[RKTestFactory baseURL]]];
RKObjectRequestOperation *requestOperation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[ userDescriptor, errorDescriptor ]];
[requestOperation start];
[requestOperation waitUntilFinished];
expect(requestOperation.error).willNot.beNil();
expect([requestOperation.error localizedDescription]).to.equal(@"Loaded an unprocessable response (500) with content type 'application/json'");
}
@end

View File

@@ -202,6 +202,11 @@ class RestKitTestServer < Sinatra::Base
content_type 'application/json'
render_fixture('/JSON/errors.json', :status => 500)
end
get '/500' do
status 500
content_type 'application/json'
end
# Expects an uploaded 'file' param
post '/api/upload/' do