Skip to content

Commit

Permalink
CRC
Browse files Browse the repository at this point in the history
  • Loading branch information
MP0w committed Jul 1, 2016
1 parent 913a884 commit f4ebeac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Source/JSONAPILinks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum JSONAPILink: CustomSerializable {
// MARK: CustomSerializable

/**
The `JSONAPILink` implementation of `CustomSerializable` returns directly the link for `.Simple` or returns a dictionary containing the link and the serialized meta for `.Object`
The `JSONAPILink` implementation of `CustomSerializable` returns directly the link for `.Simple` or returns a dictionary containing the link (href key) and the serialized meta object (meta key) for `.Object`
*/
public func customSerialize(keyTransformer: KeyTransformer?) -> AnyObject? {
switch self {
Expand Down
69 changes: 38 additions & 31 deletions Tests/JSONAPIErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class JSONAPIErrorsSpec: QuickSpec {
return JSON(object.serialize()!)
}

describe("JSON API errors") {
describe("JSONAPIError") {

it("should serialize errors") {
it("should serialize the error") {
let error = JSONAPIError(statusCode: 404) { (error) in
error.title = "test"
}
Expand All @@ -54,41 +54,48 @@ class JSONAPIErrorsSpec: QuickSpec {
expect(meta["description"]).to(equal("test"))
}

it("should affect the status code of the request") {
let router = Router.register("http://www.test.com")
context("Provides response fields") {

router.get("/users"){ request in
return JSONAPIError(statusCode: 501) { (error) in
error.title = "test"
}
afterEach {
Router.disableAll()
}

var statusCode: Int = -1
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "http://www.test.com/users")!) { (data, response, _) in
let response = response as! NSHTTPURLResponse
statusCode = response.statusCode
}.resume()

expect(statusCode).toEventually(equal(501))
}

it("should affect the header fields of the response") {
let router = Router.register("http://www.test.com")

router.get("/users"){ request in
return JSONAPIError(statusCode: 501, headerFields: ["foo": "bar"]) { (error) in
error.title = "test"
it("should affect the status code of the request") {
let router = Router.register("http://www.test.com")

router.get("/users"){ request in
return JSONAPIError(statusCode: 501) { (error) in
error.title = "test"
}
}

var statusCode: Int = -1
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "http://www.test.com/users")!) { (data, response, _) in
let response = response as! NSHTTPURLResponse
statusCode = response.statusCode
}.resume()

expect(statusCode).toEventually(equal(501))
}

var foo: String?
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "http://www.test.com/users")!) { (data, response, _) in
let response = response as! NSHTTPURLResponse
let headers = response.allHeaderFields as? [String: String]
foo = headers?["foo"]
}.resume()

expect(foo).to(equal("bar"))
it("should affect the header fields of the response") {
let router = Router.register("http://www.test.com")

router.get("/users"){ request in
return JSONAPIError(statusCode: 501, headerFields: ["foo": "bar"]) { (error) in
error.title = "test"
}
}

var foo: String?
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "http://www.test.com/users")!) { (data, response, _) in
let response = response as! NSHTTPURLResponse
let headers = response.allHeaderFields as? [String: String]
foo = headers?["foo"]
}.resume()

expect(foo).toEventually(equal("bar"))
}
}
}
}
Expand Down

0 comments on commit f4ebeac

Please sign in to comment.