forked from mirror/gorm
NewRecord should also works with struct pointer
This commit is contained in:
parent
660ee1ed73
commit
96ade8c619
|
@ -166,6 +166,10 @@ func TestCreateAndUpdate(t *testing.T) {
|
||||||
t.Error("User should be new record")
|
t.Error("User should be new record")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !db.NewRecord(&user) {
|
||||||
|
t.Error("User should be new record")
|
||||||
|
}
|
||||||
|
|
||||||
db.Save(&user)
|
db.Save(&user)
|
||||||
if user.Id == 0 {
|
if user.Id == 0 {
|
||||||
t.Errorf("Should have ID after create")
|
t.Errorf("Should have ID after create")
|
||||||
|
@ -175,6 +179,10 @@ func TestCreateAndUpdate(t *testing.T) {
|
||||||
t.Error("User should not new record after save")
|
t.Error("User should not new record after save")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if db.NewRecord(&user) {
|
||||||
|
t.Error("User should not new record after save")
|
||||||
|
}
|
||||||
|
|
||||||
var u User
|
var u User
|
||||||
db.First(&u, user.Id)
|
db.First(&u, user.Id)
|
||||||
if !reflect.DeepEqual(u.PasswordHash, []byte{'f', 'a', 'k', '4'}) {
|
if !reflect.DeepEqual(u.PasswordHash, []byte{'f', 'a', 'k', '4'}) {
|
||||||
|
|
Loading…
Reference in New Issue