Skip to content

Commit

Permalink
Merge pull request #21 from alickbass/fix-decimal-encoding
Browse files Browse the repository at this point in the history
Fix handling decimal value
  • Loading branch information
Oleksii Dykan authored Feb 11, 2018
2 parents df9dfe1 + 0c60f70 commit b0e8686
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CodableFirebase/Encoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ extension _FirebaseEncoder {
return try self.box((value as! Data))
} else if T.self == URL.self || T.self == NSURL.self {
return self.box((value as! URL).absoluteString)
} else if T.self == Decimal.self || T.self == NSDecimalNumber.self {
return (value as! NSDecimalNumber)
} else if options.skipFirestoreTypes && (value is FirestoreEncodable) {
guard let value = value as? NSObject else {
throw DocumentReferenceError.typeIsNotNSObject
Expand Down
5 changes: 5 additions & 0 deletions CodableFirebaseTests/TestCodableFirestore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class TestCodableFirestore: XCTestCase {
_testRoundTrip(of: TopLevelWrapper(date), expected: ["value": date])
}

func testDecimalValue() {
let value = Decimal(2)
_testRoundTrip(of: TopLevelWrapper(value), expected: ["value": value])
}

// MARK: - GeoPoint & Document Reference
func testEncodingGeoPoint() {
let point = GeoPoint(latitude: 2, longitude: 2)
Expand Down

0 comments on commit b0e8686

Please sign in to comment.