BeforeSave test failed
BeforeSave event called but struct not changed
Sql update is broken, because doesn't have id column
```
INSERT INTO "uuid_structs" ("name") VALUES ('')
```
			
			
This commit is contained in:
		
							parent
							
								
									373207d546
								
							
						
					
					
						commit
						bd0aed633e
					
				
							
								
								
									
										21
									
								
								main_test.go
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								main_test.go
									
									
									
									
									
								
							@ -95,6 +95,27 @@ func TestStringPrimaryKey(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type UUIDStruct struct {
 | 
			
		||||
	ID   string `gorm:"primary_key"`
 | 
			
		||||
	Name string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *UUIDStruct) BeforeSave() {
 | 
			
		||||
	u.ID = "new_uuid"
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestBeforeSaveGenerateId(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	DB.DropTable(&UUIDStruct{})
 | 
			
		||||
	DB.AutoMigrate(&UUIDStruct{})
 | 
			
		||||
 | 
			
		||||
	data := UUIDStruct{}
 | 
			
		||||
	if err := DB.Save(&data).Error; err != nil || data.ID != "new_uuid" {
 | 
			
		||||
		t.Errorf("string primary key should be changed")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestExceptionsWithInvalidSql(t *testing.T) {
 | 
			
		||||
	var columns []string
 | 
			
		||||
	if DB.Where("sdsd.zaaa = ?", "sd;;;aa").Pluck("aaa", &columns).Error == nil {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user