Skip to content

Commit

Permalink
Add test to ensure pokebgh-211 stays fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pokeb committed Aug 6, 2011
1 parent e7fff59 commit 6eac3fb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Classes/ASIHTTPRequest.m
Expand Up @@ -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;

Expand Down
29 changes: 29 additions & 0 deletions Classes/Tests/ASIDownloadCacheTests.m
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Mac.xcodeproj/project.pbxproj
Expand Up @@ -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";
Expand Down

0 comments on commit 6eac3fb

Please sign in to comment.