Skip to content

Commit e98e573

Browse files
committed
add test for custom table name in update tests
1 parent 5e16f5f commit e98e573

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

tests/migrate_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,15 +2178,3 @@ func TestMigrateOnUpdateConstraint(t *testing.T) {
21782178
panic(fmt.Errorf("company id is not equal: expects: %v, got: %v", 0, updatedPen3.OwnerID))
21792179
}
21802180
}
2181-
2182-
func TestUpdateWithCustomTableName(t *testing.T) {
2183-
sql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
2184-
return tx.Clauses(clause.Update{
2185-
Table: clause.Table{Name: "custom_update_table"},
2186-
}).Where("id = ?", 200).
2187-
Updates(&User{Name: "patched", Age: 99})
2188-
})
2189-
2190-
assertEqualSQL(t, `UPDATE "custom_update_table" SET "updated_at"=?,"name"='patched',"age"=99 WHERE id = 200 AND "custom_update_table"."deleted_at" IS NULL`, sql)
2191-
2192-
}

tests/update_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,3 +1163,15 @@ func TestUpdateCustomDataType(t *testing.T) {
11631163
t.Errorf("failed to update custom data type field: %v", err)
11641164
}
11651165
}
1166+
1167+
func TestUpdateWithCustomTableName(t *testing.T) {
1168+
sql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
1169+
return tx.Clauses(clause.Update{
1170+
Table: clause.Table{Name: "custom_update_table"},
1171+
}).Where("id = ?", 200).
1172+
Updates(&User{Name: "patched", Age: 99})
1173+
})
1174+
1175+
assertEqualSQL(t, `UPDATE "custom_update_table" SET "updated_at"=?,"name"='patched',"age"=99 WHERE id = 200 AND "custom_update_table"."deleted_at" IS NULL`, sql)
1176+
1177+
}

0 commit comments

Comments
 (0)