mirror of https://github.com/go-gorm/gorm.git
test: add testcase in TestSave
This commit is contained in:
parent
1d9e563023
commit
c898622791
tests
|
@ -642,6 +642,36 @@ func TestSave(t *testing.T) {
|
|||
if !regexp.MustCompile("WHERE .id. = [^ ]+$").MatchString(stmt.SQL.String()) {
|
||||
t.Fatalf("invalid updating SQL, got %v", stmt.SQL.String())
|
||||
}
|
||||
|
||||
user3 := *GetUser("save3", Config{})
|
||||
DB.Create(&user3)
|
||||
|
||||
if err := DB.First(&User{}, "name = ?", "save3").Error; err != nil {
|
||||
t.Fatalf("failed to find created user")
|
||||
}
|
||||
|
||||
user3.Name = "save3_"
|
||||
DB.Model(User{}).Save(&user3)
|
||||
|
||||
var result2 User
|
||||
if err := DB.First(&result2, "name = ?", "save3_").Error; err != nil || result2.ID != user3.ID {
|
||||
t.Fatalf("failed to find updated user")
|
||||
}
|
||||
|
||||
DB.Model(User{}).Save(&struct {
|
||||
gorm.Model
|
||||
Placeholder string
|
||||
Name string
|
||||
}{
|
||||
Model: user3.Model,
|
||||
Placeholder: "placeholder",
|
||||
Name: "save3__",
|
||||
})
|
||||
|
||||
var result3 User
|
||||
if err := DB.First(&result3, "name = ?", "save3__").Error; err != nil || result3.ID != user3.ID {
|
||||
t.Fatalf("failed to find updated user")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveWithPrimaryValue(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue