Skip to content

Commit

Permalink
Update field encoding so that it uses the generic path
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed Sep 6, 2022
1 parent 055a858 commit aabce0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/Meow/KeyPathModel/KeyPathModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ public struct Field<C: Codable>: Codable {
}

public func encode(to encoder: Encoder) throws {
try _wrappedValue!.encode(to: encoder)
var container = encoder.singleValueContainer()
try container.encode(_wrappedValue!)
}
}

Expand Down
11 changes: 11 additions & 0 deletions Tests/MeowTests/MeowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class MeowTests: XCTestCase {
self.meow = MeowDatabase(mongo)
}

func testEncodeDate() throws {
struct Entity: Model {
@Field var _id: ObjectId
@Field var date: Date
}

let entity = Entity(_id: ObjectId(), date: Date())
let document = try BSONEncoder().encode(entity)
XCTAssertTrue(document["date"] is Date)
}

func testAggregate() async throws {
_ = try await meow[User.self].buildCheckedAggregate {
Match<User> { user in
Expand Down

0 comments on commit aabce0b

Please sign in to comment.