Skip to content

Commit

Permalink
add uint8-backed enum test (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 authored Dec 26, 2019
1 parent 27d8b35 commit 877bf49
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Sources/FluentBenchmark/FluentBenchmarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public final class FluentBenchmarker {
try self.testSoftDeleteWithQuery()
try self.testDuplicatedUniquePropertyName()
try self.testEmptyEagerLoadChildren()
try self.testUInt8BackedEnum()
}

public func testCreate() throws {
Expand Down Expand Up @@ -1775,6 +1776,50 @@ public final class FluentBenchmarker {
XCTAssertEqual(galaxies.count, 0)
}
}

public func testUInt8BackedEnum() throws {
enum Bar: UInt8, Codable {
case baz, qux
}
final class Foo: Model {
static let schema = "foos"

struct _Migration: Migration {
func prepare(on database: Database) -> EventLoopFuture<Void> {
return database.schema("foos")
.field("id", .int, .identifier(auto: true))
.field("bar", .uint8, .required)
.create()
}

func revert(on database: Database) -> EventLoopFuture<Void> {
return database.schema("foos").delete()
}
}

@ID(key: "id")
var id: Int?

@Field(key: "bar")
var bar: Bar

init() { }

init(id: Int? = nil, bar: Bar) {
self.id = id
self.bar = bar
}
}
try runTest(#function, [
Foo._Migration()
]) {
let foo = Foo(bar: .baz)
try foo.save(on: self.database).wait()

let fetched = try Foo.find(foo.id, on: self.database).wait()
XCTAssertEqual(fetched?.bar, .baz)
}
}

// MARK: Utilities

Expand Down

0 comments on commit 877bf49

Please sign in to comment.