Skip to content

Commit 39efcb8

Browse files
committed
add test
1 parent 158e86c commit 39efcb8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tests/hooks_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -610,35 +610,35 @@ func TestPropagateUnscoped(t *testing.T) {
610610
}
611611
}
612612

613-
type UserUpdate struct {
613+
type StructUpdate struct {
614614
ID uint `gorm:"column:id;primary_key"`
615615
Version int `gorm:"column:version"`
616616
Name string `gorm:"column:name"`
617617
}
618618

619-
func (UserUpdate) TableName() string {
620-
return "user_updates"
619+
func (StructUpdate) TableName() string {
620+
return "struct_updates"
621621
}
622622

623-
func (up *UserUpdate) BeforeUpdate(tx *gorm.DB) error {
623+
func (up *StructUpdate) BeforeUpdate(tx *gorm.DB) error {
624624
up.Version++
625625
return nil
626626
}
627627

628628
func TestBeforeUpdateWithStructColumn(t *testing.T) {
629-
DB.Migrator().DropTable(&UserUpdate{})
630-
DB.AutoMigrate(&UserUpdate{})
629+
DB.Migrator().DropTable(&StructUpdate{})
630+
DB.AutoMigrate(&StructUpdate{})
631631

632-
user := UserUpdate{
632+
su := StructUpdate{
633633
ID: 1,
634634
Version: 1,
635635
}
636-
DB.Create(&user)
636+
DB.Create(&su)
637637

638638
sql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
639-
return DB.Model(&user).Update("name", "demoManito")
639+
return DB.Model(&su).Update("name", "demoManito")
640640
})
641-
if sql != "UPDATE `user_updates` SET `user_updates`.`name` = `demoManito`, `user_updates`.`version` = 2 WHERE `user_updates`.`id` = 1" {
641+
if sql != "UPDATE `struct_updates` SET `user_updates`.`name` = `demoManito`, `user_updates`.`version` = 2 WHERE `user_updates`.`id` = 1" {
642642
t.Fatalf("invalid sql: %v", sql)
643643
}
644644
}

0 commit comments

Comments
 (0)