Skip to content

Commit

Permalink
Added tests around the UIImageView extension usage with redirect URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed Sep 23, 2015
1 parent 2cf140a commit aa7e14e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/UIImageView+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ extension UIImageView {
completion: { [weak self] request, response, result in
guard let strongSelf = self else { return }

// Ignore the event if the response request does not match the current request
// Ignore the event if the response request does not match the original request
guard let
currentRequest = strongSelf.af_activeRequest?.task.originalRequest
where currentRequest.URLString == request?.URLString else
Expand Down
24 changes: 24 additions & 0 deletions Tests/UIImageViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,28 @@ class UIImageViewTestCase: BaseTestCase {
XCTAssertNotNil(imageView.image, "image view image should not be nil when completion handler is not nil")
XCTAssertTrue(result?.isSuccess ?? false, "result should be a success case")
}

// MARK: - Redirects

func testThatImageBehindRedirectCanBeDownloaded() {
// Given
let redirectURLString = "https://httpbin.org/image/png"
let URL = NSURL(string: "https://httpbin.org/redirect-to?url=\(redirectURLString)")!

let expectation = expectationWithDescription("image should download successfully")
var imageDownloadComplete = false

let imageView = TestImageView {
imageDownloadComplete = true
expectation.fulfill()
}

// When
imageView.af_setImageWithURL(URL)
waitForExpectationsWithTimeout(timeout, handler: nil)

// Then
XCTAssertTrue(imageDownloadComplete, "image download complete should be true")
XCTAssertNotNil(imageView.image, "image view image should not be nil")
}
}

0 comments on commit aa7e14e

Please # to comment.