update tests

This commit is contained in:
Jinzhu 2014-01-05 09:37:15 +08:00
parent 30e1b07f7e
commit d8f7d4a243
1 changed files with 10 additions and 10 deletions

View File

@ -1471,34 +1471,34 @@ func TestSqlNullValue(t *testing.T) {
} }
func TestTransaction(t *testing.T) { func TestTransaction(t *testing.T) {
d := db.Begin() tx := db.Begin()
u := User{Name: "transcation"} u := User{Name: "transcation"}
if err := d.Save(&u).Error; err != nil { if err := tx.Save(&u).Error; err != nil {
t.Errorf("No error should raise, but got", err) t.Errorf("No error should raise, but got", err)
} }
if err := d.First(&User{}, "name = ?", "transcation").Error; err != nil { if err := tx.First(&User{}, "name = ?", "transcation").Error; err != nil {
t.Errorf("Should find saved record, but got", err) t.Errorf("Should find saved record, but got", err)
} }
d.Rollback() tx.Rollback()
if err := d.First(&User{}, "name = ?", "transcation").Error; err == nil { if err := tx.First(&User{}, "name = ?", "transcation").Error; err == nil {
t.Errorf("Should not find record after rollback") t.Errorf("Should not find record after rollback")
} }
d2 := db.Begin() tx2 := db.Begin()
u2 := User{Name: "transcation-2"} u2 := User{Name: "transcation-2"}
if err := d2.Save(&u2).Error; err != nil { if err := tx2.Save(&u2).Error; err != nil {
t.Errorf("No error should raise, but got", err) t.Errorf("No error should raise, but got", err)
} }
d2.Update("age", 90) tx2.Update("age", 90)
if err := d2.First(&User{}, "name = ?", "transcation-2").Error; err != nil { if err := tx2.First(&User{}, "name = ?", "transcation-2").Error; err != nil {
t.Errorf("Should find saved record, but got", err) t.Errorf("Should find saved record, but got", err)
} }
d2.Commit() tx2.Commit()
if err := db.First(&User{}, "name = ?", "transcation-2").Error; err != nil { if err := db.First(&User{}, "name = ?", "transcation-2").Error; err != nil {
t.Errorf("Should be able to find committed record") t.Errorf("Should be able to find committed record")