-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from ishkawa/feature/fix-url-encoding
Fix parameter encoding in GET request
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import XCTest | ||
import OHHTTPStubs | ||
import APIKit | ||
|
||
class RequestTests: XCTestCase { | ||
struct SearchRequest: MockAPIRequest { | ||
let query: String | ||
|
||
// MARK: Request | ||
typealias Response = [String: AnyObject] | ||
|
||
var method: HTTPMethod { | ||
return .GET | ||
} | ||
|
||
var path: String { | ||
return "/" | ||
} | ||
|
||
var parameters: [String: AnyObject] { | ||
return [ | ||
"q": query, | ||
] | ||
} | ||
|
||
func responseFromObject(object: AnyObject, URLResponse: NSHTTPURLResponse) -> Response? { | ||
return object as? [String: AnyObject] | ||
} | ||
} | ||
|
||
override func tearDown() { | ||
OHHTTPStubs.removeAllStubs() | ||
super.tearDown() | ||
} | ||
|
||
func testURLQueryParameterEncoding() { | ||
OHHTTPStubs.stubRequestsPassingTest({ request in | ||
XCTAssert(request.URL?.query == "q=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF") | ||
return true | ||
}, withStubResponse: { request in | ||
return OHHTTPStubsResponse(data: NSData(), statusCode: 200, headers: nil) | ||
}) | ||
|
||
let request = SearchRequest(query: "こんにちは") | ||
let expectation = expectationWithDescription("waiting for the response.") | ||
|
||
API.sendRequest(request) { result in | ||
expectation.fulfill() | ||
} | ||
|
||
waitForExpectationsWithTimeout(1.0, handler: nil) | ||
} | ||
} |