Add comments

This commit is contained in:
Jacques Racagneres 2019-09-27 01:50:27 +01:00
parent 474edd63a7
commit 4f235aab52
No known key found for this signature in database
GPG Key ID: 284DB65BF94294AF

View File

@ -434,8 +434,7 @@ type NewPerson struct {
} }
func TestAssociatedBlankValues(t *testing.T) { func TestAssociatedBlankValues(t *testing.T) {
DB.LogMode(true) // Create person
person1 := NewPerson{ person1 := NewPerson{
ID: 1, ID: 1,
Name: "Person", Name: "Person",
@ -448,6 +447,7 @@ func TestAssociatedBlankValues(t *testing.T) {
DB.Save(&person1) DB.Save(&person1)
// Update person only updating house number
person1Update := NewPerson{ person1Update := NewPerson{
ID: 1, ID: 1,
NewAddress: NewAddress{ NewAddress: NewAddress{
@ -457,17 +457,21 @@ func TestAssociatedBlankValues(t *testing.T) {
} }
DB.Model(&person1Update).Update(person1Update) DB.Model(&person1Update).Update(person1Update)
// Get person back from database
var personGet NewPerson var personGet NewPerson
DB.Preload("NewAddress").Find(&personGet) DB.Preload("NewAddress").Find(&personGet)
// Check that LineOne hasn't changed
if personGet.NewAddress.LineOne != "Street One" { if personGet.NewAddress.LineOne != "Street One" {
t.Errorf("line one should be 'Street One' as it was updated with a blank value. Value is %s", personGet.NewAddress.LineOne) t.Errorf("line one should be 'Street One' as it was updated with a blank value. Value is %s", personGet.NewAddress.LineOne)
} }
// Ensure house number has updated
if personGet.NewAddress.HouseNumber != 2 { if personGet.NewAddress.HouseNumber != 2 {
t.Errorf("house number should be 2 following the update. Value is %d", personGet.NewAddress.HouseNumber) t.Errorf("house number should be 2 following the update. Value is %d", personGet.NewAddress.HouseNumber)
} }
// Check that Person is still the original value
if personGet.Name != "Person" { if personGet.Name != "Person" {
t.Errorf("name should be 'Person' as it was updated with a blank value. Value is %s", personGet.Name) t.Errorf("name should be 'Person' as it was updated with a blank value. Value is %s", personGet.Name)
} }