From 5fd2fe7462d91be41c9f27439cc9ae16f9d5c61a Mon Sep 17 00:00:00 2001 From: sgsv <-> Date: Thu, 9 May 2024 17:06:38 +0200 Subject: [PATCH] Add has one panic test --- tests/associations_has_one_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/associations_has_one_test.go b/tests/associations_has_one_test.go index a2c07509..78290ce9 100644 --- a/tests/associations_has_one_test.go +++ b/tests/associations_has_one_test.go @@ -255,3 +255,15 @@ func TestPolymorphicHasOneAssociationForSlice(t *testing.T) { DB.Model(&pets).Association("Toy").Clear() AssertAssociationCount(t, pets, "Toy", 0, "After Clear") } + +func TestHasOneAssociationReplaceWithNonValidValue(t *testing.T) { + user := User{Name: "jinzhu", Account: Account{Number: "1"}} + + if err := DB.Create(&user).Error; err != nil { + t.Fatalf("errors happened when create: %v", err) + } + + if err := DB.Model(&user).Association("Languages").Replace(Account{Number: "2"}); err == nil { + t.Error("expected association error to be not nil") + } +}