Skip to content

Commit

Permalink
Merge pull request #27 from MrMage/fix-date-precision
Browse files Browse the repository at this point in the history
Add tests to ensure that a date's millisecond part is persisted.
  • Loading branch information
tanner0101 committed Mar 13, 2018
2 parents bc8d802 + d1eda98 commit a6d274e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Tests/FluentPostgreSQLTests/FluentPostgreSQLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ class FluentPostgreSQLTests: XCTestCase {
XCTAssertEqual(dogs.count, 1)
XCTAssertEqual(dogs.first?.name, "Spud")
}

func testPersistsDateMillisecondPart() throws {
database.enableLogging(using: DatabaseLogger(handler: { print($0) }))
let conn = try database.makeConnection(on: eventLoop).await(on: eventLoop)
try? DefaultTest.revert(on: conn).await(on: eventLoop)
try DefaultTest.prepare(on: conn).await(on: eventLoop)
var test = DefaultTest()
test.date = PostgreSQLDate(Date(timeIntervalSinceReferenceDate: 123.456))
_ = try test.save(on: conn).await(on: eventLoop)
let fetched = try DefaultTest.query(on: conn).first().await(on: eventLoop)!
XCTAssertEqual(123.456, fetched.date!.value!.timeIntervalSinceReferenceDate, accuracy: 1e-6)
try DefaultTest.revert(on: conn).await(on: eventLoop)
conn.close()
}

static let allTests = [
("testSchema", testSchema),
Expand Down

0 comments on commit a6d274e

Please sign in to comment.