Add tests for updated_at will be updated when update value with Assign

This commit is contained in:
Jinzhu 2014-02-18 10:03:14 +08:00
parent c25f26149e
commit 2c33502503
3 changed files with 8 additions and 3 deletions

View File

@ -8,8 +8,8 @@ import (
type DB struct {
Value interface{}
callback *callback
Error error
callback *callback
db sqlCommon
parent *DB
search *search

View File

@ -10,7 +10,6 @@ import (
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
_ "github.com/mattn/go-sqlite3"
"os"
"reflect"
@ -1105,6 +1104,12 @@ func TestFindOrCreate(t *testing.T) {
t.Errorf("user should be created with search value and attrs")
}
updated_at1 := user4.UpdatedAt
db.Where(&User{Name: "find or create 3"}).Assign("age", 55).FirstOrCreate(&user4)
if updated_at1.Format(time.RFC3339Nano) == user4.UpdatedAt.Format(time.RFC3339Nano) {
t.Errorf("UpdateAt should be changed when update values with assign")
}
db.Where(&User{Name: "find or create 4"}).Assign(User{Age: 44}).FirstOrCreate(&user4)
if user4.Name != "find or create 4" || user4.Id == 0 || user4.Age != 44 {
t.Errorf("user should be created with search value and assigned attrs")

View File

@ -324,7 +324,7 @@ func (scope *Scope) sqlTagForField(field *Field) (tag string) {
}
}
if len(tag) == 0 && tag != "-" {
if len(tag) == 0 {
if field.isPrimaryKey {
tag = scope.Dialect().PrimaryKeyTag(value, size)
} else {