Add some delete tests

This commit is contained in:
Jinzhu 2013-10-26 21:51:44 +08:00
parent f4f7e44199
commit 3d50000094
2 changed files with 19 additions and 1 deletions

View File

@ -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
View File

@ -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
} }