Ensure record ID changes are detected in diff

This commit is contained in:
Tobie Morgan Hitchcock 2018-11-29 10:44:17 +00:00
parent 38f0e3469e
commit 3d4081bd54
2 changed files with 12 additions and 3 deletions

View file

@ -277,7 +277,7 @@ func (o *operations) vals(old, now interface{}, path string) {
}
case *sql.Thing:
nv := now.(*sql.Thing)
if ov.TB != nv.TB && ov.ID != nv.ID {
if ov.TB != nv.TB || ov.ID != nv.ID {
o.op("replace", "", path, old, now)
}
case bool:

View file

@ -17,11 +17,14 @@ package diff
import (
"testing"
"github.com/abcum/surreal/sql"
. "github.com/smartystreets/goconvey/convey"
)
var old = map[string]interface{}{
"age": 18,
"item": sql.NewThing("test", 1),
"name": map[string]interface{}{
"first": "T",
"last": "M H",
@ -33,6 +36,7 @@ var old = map[string]interface{}{
var now = map[string]interface{}{
"age": 29,
"item": sql.NewThing("test", 2),
"name": map[string]interface{}{
"first": "Tobie",
"last": "Morgan Hitchcock",
@ -97,6 +101,11 @@ var chg = []interface{}{
"path": "/different",
"value": true,
},
map[string]interface{}{
"op": "replace",
"path": "/item",
"value": sql.NewThing("test", 2),
},
map[string]interface{}{
"op": "change",
"path": "/name/first",