swap out broken nil checks (not harming anything, but not working as evidenced by not getting hit by any test cases)

This commit is contained in:
Mathew Polzin
2019-07-29 21:00:44 -07:00
parent f5eb343bd4
commit 396f8453d1
3 changed files with 9 additions and 8 deletions
+6 -4
View File
@@ -71,10 +71,12 @@ extension SingleResourceBody {
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
if (value as Any?) == nil {
try container.encodeNil()
return
}
let anyNil: Any? = nil
let nilValue = anyNil as? Entity
guard value != nilValue else {
try container.encodeNil()
return
}
try container.encode(value)
}
@@ -190,10 +190,6 @@ extension ToOneRelationship: Codable where Identifiable.Identifier: OptionalId {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: ResourceLinkageCodingKeys.self)
if (id as Any?) == nil {
try container.encodeNil(forKey: .data)
}
if MetaType.self != NoMetadata.self {
try container.encode(meta, forKey: .meta)
}
@@ -100,6 +100,9 @@ class ResourceBodyTests: XCTestCase {
XCTAssertEqual(combined.values.count, 3)
XCTAssertEqual(combined.values, body1.values + body2.values)
}
}
extension ResourceBodyTests {
enum ArticleType: ResourceObjectDescription {
public static var jsonType: String { return "articles" }