Added specs for zero-length Content-Length header when params is nil or empty

This commit is contained in:
Blake Watters
2011-07-20 21:55:10 -04:00
parent 67648a24a0
commit ae29401841
6 changed files with 88 additions and 8 deletions

View File

@@ -178,7 +178,9 @@
if ([_params respondsToSelector:@selector(HTTPHeaderValueForContentLength)]) {
[_URLRequest setValue:[NSString stringWithFormat:@"%d", [_params HTTPHeaderValueForContentLength]] forHTTPHeaderField:@"Content-Length"];
}
}
} else {
[_URLRequest setValue:@"0" forHTTPHeaderField:@"Content-Length"];
}
// Add authentication headers so we don't have to deal with an extra cycle for each message requiring basic auth.
if (self.forceBasicAuthentication) {

View File

@@ -31,7 +31,6 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
13924B7913AAB91700DD5078 /* libUISpec.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13924B7813AAB91700DD5078 /* libUISpec.a */; };
25064735138DF17C0002F2FE /* RKManagedObjectSeeder.m in Sources */ = {isa = PBXBuildFile; fileRef = 253A088912551D8D00976E89 /* RKManagedObjectSeeder.m */; };
250C296C13411E60000A3551 /* RKRequestQueueSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 250C296B13411E60000A3551 /* RKRequestQueueSpec.m */; };
250C29FD134185D2000A3551 /* RKNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 250C29FB134185CE000A3551 /* RKNetwork.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -110,6 +109,7 @@
256FD651112C7B780077F340 /* RKMappableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FD64F112C7B780077F340 /* RKMappableObject.m */; };
256FD652112C7B780077F340 /* RKMappableAssociation.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FD650112C7B780077F340 /* RKMappableAssociation.m */; };
256FDE55112DB0B90077F340 /* RKObjectMapperSpecModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FDE54112DB0B90077F340 /* RKObjectMapperSpecModel.m */; };
25716F6F13D7979A00572BD9 /* libUISpec.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13924B7513AAB8F500DD5078 /* libUISpec.a */; };
257D2D7013759D70008E9649 /* RKObjectMappingResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 257D2D6E13759D6F008E9649 /* RKObjectMappingResult.h */; settings = {ATTRIBUTES = (Public, ); }; };
257D2D7113759D70008E9649 /* RKObjectMappingResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 257D2D6F13759D6F008E9649 /* RKObjectMappingResult.m */; };
257FB677139559A4003A628E /* RKManagedObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 257FB675139559A4003A628E /* RKManagedObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -755,7 +755,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
13924B7913AAB91700DD5078 /* libUISpec.a in Frameworks */,
25716F6F13D7979A00572BD9 /* libUISpec.a in Frameworks */,
25A1CB50138419D900A7D5C9 /* libRestKitJSONParserJSONKit.a in Frameworks */,
25A1CB51138419D900A7D5C9 /* libRestKitJSONParserSBJSON.a in Frameworks */,
25A1CB52138419D900A7D5C9 /* libRestKitXMLParserLibxml.a in Frameworks */,

View File

@@ -49,7 +49,7 @@
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
enablesOpenGLESFrameCapture = "YES">
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
@@ -87,13 +87,13 @@
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_SPEC"
value = "RKManagedObjectStoreSpec"
value = "RKRequestSpec"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_EXAMPLE"
value = "itShouldAllowYouToPOSTAnObjectAndMapBackNonNestedContent"
isEnabled = "NO">
value = "itShouldPUTWithParams"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "NSAutoreleaseHaltOnNoPool"
@@ -110,7 +110,8 @@
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release">
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"

View File

@@ -535,4 +535,39 @@
[loader waitForResponse];
assertThat([loader.response bodyAsString], is(equalTo(@"{\"username\":\"hello\",\"password\":\"password\"}")));
}
- (void)itShouldSetAnEmptyContentBodyWhenParamsIsNil {
RKClient* client = RKSpecNewClient();
client.cachePolicy = RKRequestCachePolicyNone;
RKSpecStubNetworkAvailability(YES);
RKSpecResponseLoader* loader = [RKSpecResponseLoader responseLoader];
loader.timeout = 20;
RKRequest* request = [client get:@"/echo_params" delegate:loader];
[loader waitForResponse];
assertThat([request.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
}
- (void)itShouldSetAnEmptyContentBodyWhenQueryParamsIsAnEmptyDictionary {
RKClient* client = RKSpecNewClient();
client.cachePolicy = RKRequestCachePolicyNone;
RKSpecStubNetworkAvailability(YES);
RKSpecResponseLoader* loader = [RKSpecResponseLoader responseLoader];
loader.timeout = 20;
RKRequest* request = [client get:@"/echo_params" queryParams:[NSDictionary dictionary] delegate:loader];
[loader waitForResponse];
assertThat([request.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
}
- (void)itShouldPUTWithParams {
RKClient* client = RKSpecNewClient();
RKParams *params = [RKParams params];
[params setValue:@"ddss" forParam:@"username"];
[params setValue:@"aaaa@aa.com" forParam:@"email"];
RKLogConfigureByName("RestKit/Network*", RKLogLevelTrace);
RKSpecResponseLoader* loader = [RKSpecResponseLoader responseLoader];
[client put:@"/ping" params:params delegate:loader];
[loader waitForResponse];
assertThat([loader.response bodyAsString], is(equalTo(@"{\"username\":\"ddss\",\"email\":\"aaaa@aa.com\"}")));
}
@end

View File

@@ -190,4 +190,40 @@
assertThat(human.name, is(equalTo(@"My Name")));
}
- (void)itShouldNotSetAContentBodyOnAGET {
RKObjectManager* objectManager = RKSpecNewObjectManager();
[objectManager.router routeClass:[RKObjectMapperSpecModel class] toResourcePath:@"/humans/1"];
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[RKObjectMapperSpecModel class]];
[mapping mapAttributes:@"name", @"age", nil];
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
RKSpecResponseLoader* responseLoader = [RKSpecResponseLoader responseLoader];
RKObjectMapperSpecModel* human = [[RKObjectMapperSpecModel new] autorelease];
human.name = @"Blake Watters";
human.age = [NSNumber numberWithInt:28];
RKObjectLoader* loader = [objectManager getObject:human delegate:responseLoader];
[responseLoader waitForResponse];
RKLogCritical(@"%@", [loader.URLRequest allHTTPHeaderFields]);
assertThat([loader.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
}
- (void)itShouldNotSetAContentBodyOnADELETE {
RKObjectManager* objectManager = RKSpecNewObjectManager();
[objectManager.router routeClass:[RKObjectMapperSpecModel class] toResourcePath:@"/humans/1"];
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[RKObjectMapperSpecModel class]];
[mapping mapAttributes:@"name", @"age", nil];
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
RKSpecResponseLoader* responseLoader = [RKSpecResponseLoader responseLoader];
RKObjectMapperSpecModel* human = [[RKObjectMapperSpecModel new] autorelease];
human.name = @"Blake Watters";
human.age = [NSNumber numberWithInt:28];
RKObjectLoader* loader = [objectManager deleteObject:human delegate:responseLoader];
[responseLoader waitForResponse];
RKLogCritical(@"%@", [loader.URLRequest allHTTPHeaderFields]);
assertThat([loader.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
}
@end

View File

@@ -95,6 +95,12 @@ class RestKit::SpecServer < Sinatra::Base
{ :firstUser => {}, :secondUser => {}}.to_json
end
put '/ping' do
status 200
content_type 'application/json'
params.to_json
end
# start the server if ruby file executed directly
run! if app_file == $0
end