From 2a03332f53cfaa617aaae38c9e18c18efe96b93d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sat, 26 Oct 2013 22:00:38 +0800 Subject: [PATCH] Update tests for Update --- orm_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/orm_test.go b/orm_test.go index e8d896d5..a662f8b2 100644 --- a/orm_test.go +++ b/orm_test.go @@ -40,31 +40,31 @@ func TestSaveAndFind(t *testing.T) { } func TestUpdate(t *testing.T) { - name := "update" + name, name2, new_name := "update", "update2", "new_update" user := User{Name: name} db.Save(&user) + db.Save(&User{Name: name2}) - user_id := user.Id - if user_id == 0 { + if user.Id == 0 { t.Errorf("User Id should exist after create") } - orm := db.Where("name = ?", "update").First(&User{}) - if orm.Error != nil { - t.Errorf("No error should raise when looking for a exiting user") - } - - user.Name = "update2" + user.Name = new_name db.Save(&user) - orm = db.Where("name = ?", "update").First(&User{}) + orm := db.Where("name = ?", name).First(&User{}) if orm.Error == nil { t.Errorf("Should raise error when looking for a existing user with an outdated name") } - orm = db.Where("name = ?", "update2").First(&User{}) + orm = db.Where("name = ?", new_name).First(&User{}) if orm.Error != nil { t.Errorf("Shouldn't raise error when looking for a existing user with the new name") } + + orm = db.Where("name = ?", name2).First(&User{}) + if orm.Error != nil { + t.Errorf("Shouldn't update other users") + } } func TestDelete(t *testing.T) {