forked from mirror/gorm
Add some delete tests
This commit is contained in:
parent
f4f7e44199
commit
3d50000094
18
orm_test.go
18
orm_test.go
|
@ -67,6 +67,24 @@ func TestUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDelete(t *testing.T) {
|
||||||
|
name, name2 := "delete", "delete2"
|
||||||
|
user := User{Name: name}
|
||||||
|
db.Save(&user)
|
||||||
|
db.Save(&User{Name: name2})
|
||||||
|
orm := db.Delete(&user)
|
||||||
|
|
||||||
|
orm = db.Where("name = ?", name).First(&User{})
|
||||||
|
if orm.Error == nil {
|
||||||
|
t.Errorf("User should be deleted successfully")
|
||||||
|
}
|
||||||
|
|
||||||
|
orm = db.Where("name = ?", name2).First(&User{})
|
||||||
|
if orm.Error != nil {
|
||||||
|
t.Errorf("User2 should not be deleted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestWhere(t *testing.T) {
|
func TestWhere(t *testing.T) {
|
||||||
name := "where"
|
name := "where"
|
||||||
db.Save(&User{Name: name})
|
db.Save(&User{Name: name})
|
||||||
|
|
2
sql.go
2
sql.go
|
@ -120,7 +120,7 @@ func (s *Orm) update(value interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Orm) deleteSql(value interface{}) {
|
func (s *Orm) deleteSql(value interface{}) {
|
||||||
s.Sql = fmt.Sprintf("DELETE FROM %v WHERE %v", s.TableName, s.whereSql)
|
s.Sql = fmt.Sprintf("DELETE FROM %v %v", s.TableName, s.whereSql())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue