From 0a97565ba892705bdaa4e5f4dee275cbbffe5808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 17 Mar 2024 13:40:18 +0100 Subject: [PATCH] Failing test for #1500 --- Tests/GRDBTests/ValueObservationTests.swift | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Tests/GRDBTests/ValueObservationTests.swift b/Tests/GRDBTests/ValueObservationTests.swift index a0d04fb5ba..f58dd103ad 100644 --- a/Tests/GRDBTests/ValueObservationTests.swift +++ b/Tests/GRDBTests/ValueObservationTests.swift @@ -1268,5 +1268,56 @@ class ValueObservationTests: GRDBTestCase { onChange: { _ in }) } + + // Regression test for + func testIssue1500() throws { + struct Foo: Codable, FetchableRecord, PersistableRecord { + var id: String + + static let bar = hasOne(Bar.self) + var bar: QueryInterfaceRequest { + 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 + }) + } }