Permalink
Browse files

Add test to ensure gh-211 stays fixed

  • Loading branch information...
1 parent e7fff59 commit 6eac3fbec87944a0e37fd11c86a1213fbe0e2d4b @pokeb committed Aug 6, 2011
Showing with 31 additions and 2 deletions.
  1. +1 −1 Classes/ASIHTTPRequest.m
  2. +29 −0 Classes/Tests/ASIDownloadCacheTests.m
  3. +1 −1 Mac.xcodeproj/project.pbxproj
View
@@ -24,7 +24,7 @@
#import "ASIDataCompressor.h"
// Automatically set on build
-NSString *ASIHTTPRequestVersion = @"v1.8.1-23 2011-08-06";
+NSString *ASIHTTPRequestVersion = @"v1.8.1-26 2011-08-06";
static NSString *defaultUserAgent = nil;
@@ -506,4 +506,33 @@ - (void)request:(ASIHTTPRequest *)request willRedirectToURL:(NSURL *)newURL
[request redirectToURL:newURL];
}
+- (void)testCachedFileOverwritten
+{
+ // Test for https://github.com/pokeb/asi-http-request/pull/211
+ // This test ensures that items in the cache are correctly overwritten when a downloadDestinationPath is set,
+ // and they need to be copied to the cache at the end of the request
+
+ // This url returns different content every time
+ NSURL *url = [NSURL URLWithString:@"http://asi/ASIHTTPRequest/tests/random-content"];
+ ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
+ [request setDownloadCache:[ASIDownloadCache sharedCache]];
+ [request setSecondsToCache:0.5f];
+ [request startSynchronous];
+
+ NSString *path = [[ASIDownloadCache sharedCache] pathToCachedResponseDataForURL:url];
+ NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
+
+ sleep(1);
+
+ request = [ASIHTTPRequest requestWithURL:url];
+ [request setDownloadCache:[ASIDownloadCache sharedCache]];
+ [request setDownloadDestinationPath:[[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"test.html"]];
+ [request startSynchronous];
+
+ NSString *content2 = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
+
+ BOOL success = ![content isEqualToString:content2];
+ GHAssertTrue(success, @"Failed to overwrite response in cache");
+}
+
@end
@@ -443,7 +443,7 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0410;
+ LastUpgradeCheck = 0420;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Mac" */;
compatibilityVersion = "Xcode 3.2";

0 comments on commit 6eac3fb

Please sign in to comment.