Skip to content

Commit

Permalink
Failing test for #1500
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Mar 17, 2024
1 parent bd9aea3 commit 0a97565
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Tests/GRDBTests/ValueObservationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1268,5 +1268,56 @@ class ValueObservationTests: GRDBTestCase {
onChange: { _ in
})
}

// Regression test for <https://github.com/groue/GRDB.swift/issues/1500>
func testIssue1500() throws {
struct Foo: Codable, FetchableRecord, PersistableRecord {
var id: String

static let bar = hasOne(Bar.self)
var bar: QueryInterfaceRequest<Bar> {
request(for: Self.bar)
}
}

struct Bar: Codable, FetchableRecord, PersistableRecord {
var fooId: String
}

var migrator = DatabaseMigrator()
migrator.registerMigration("v1") { db in
try db.create(table: "foo") { t in
t.column("id", .text).notNull().primaryKey()
}

try db.create(table: "bar") { t in
t.autoIncrementedPrimaryKey("id")
t.column("fooId", .text).notNull().unique().references("foo", onDelete: .cascade)
}
}

let pool = try makeDatabasePool()
try! pool.read { db in
if try migrator.hasBeenSuperseded(db) {
fatalError()
}
}

try! migrator.migrate(pool)

let observation = ValueObservation.trackingConstantRegion { db in
try Foo
.including(optional: Foo.bar)
.fetchOne(db)
}

let cancellable = observation.start(
in: pool,
scheduling: .immediate,
onError: { error in
XCTFail("Unexpected error \(error)")
},
onChange: { _ in
})
}
}

0 comments on commit 0a97565

Please sign in to comment.