Skip to content

Commit 200ddb2

Browse files
committed
Fix TestOverrideJoinTable by ignoring OnConflict errors as doNothing
flag is set to true during SaveAfterAssociations. This change also removes skip() for passed join test.
1 parent 97118aa commit 200ddb2

File tree

5 files changed

+3
-17
lines changed

5 files changed

+3
-17
lines changed

oracle/clause_builder.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ func OnConflictClauseBuilder(c clause.Clause, builder clause.Builder) {
300300
if len(conflictColumns) == 0 {
301301
// If no columns specified, try to use primary key fields as default
302302
if stmt.Schema == nil || len(stmt.Schema.PrimaryFields) == 0 {
303-
stmt.AddError(fmt.Errorf("OnConflict requires either explicit columns or primary key fields"))
304303
return
305304
}
306305
for _, primaryField := range stmt.Schema.PrimaryFields {

oracle/create.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ func buildBulkInsertPLSQL(db *gorm.DB, createValues clause.Values) {
219219
conflictColumns := onConflict.Columns
220220
if len(conflictColumns) == 0 {
221221
if len(schema.PrimaryFields) == 0 {
222-
db.AddError(fmt.Errorf("OnConflict requires either explicit columns or primary key fields"))
223222
return
224223
}
225224
for _, primaryField := range schema.PrimaryFields {
@@ -255,7 +254,6 @@ func buildBulkMergePLSQL(db *gorm.DB, createValues clause.Values, onConflictClau
255254
conflictColumns := onConflict.Columns
256255
if len(conflictColumns) == 0 {
257256
if schema == nil || len(schema.PrimaryFields) == 0 {
258-
db.AddError(fmt.Errorf("OnConflict requires either explicit columns or primary key fields"))
259257
return
260258
}
261259
for _, primaryField := range schema.PrimaryFields {

tests/joins_table_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ type PersonAddress struct {
6666
}
6767

6868
func TestOverrideJoinTable(t *testing.T) {
69-
t.Skip()
7069
DB.Migrator().DropTable(&Person{}, &Address{}, &PersonAddress{})
7170

7271
if err := DB.SetupJoinTable(&Person{}, "Addresses", &PersonAddress{}); err != nil {
@@ -95,7 +94,7 @@ func TestOverrideJoinTable(t *testing.T) {
9594
t.Fatalf("Should have one address left")
9695
}
9796

98-
if DB.Find(&[]PersonAddress{}, "person_id = ?", person.ID).RowsAffected != 1 {
97+
if DB.Find(&[]PersonAddress{}, "\"person_id\" = ?", person.ID).RowsAffected != 1 {
9998
t.Fatalf("Should found one address")
10099
}
101100

@@ -113,7 +112,7 @@ func TestOverrideJoinTable(t *testing.T) {
113112
t.Fatalf("Failed to find address, got error %v, length: %v", err, len(addresses3))
114113
}
115114

116-
if DB.Unscoped().Find(&[]PersonAddress{}, "person_id = ?", person.ID).RowsAffected != 2 {
115+
if DB.Unscoped().Find(&[]PersonAddress{}, "\"person_id\" = ?", person.ID).RowsAffected != 2 {
117116
t.Fatalf("Should found soft deleted addresses with unscoped")
118117
}
119118

tests/joins_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import (
5252
)
5353

5454
func TestJoins(t *testing.T) {
55-
t.Skip()
5655
user := *GetUser("joins-1", Config{Company: true, Manager: true, Account: true, NamedPet: false})
5756

5857
DB.Create(&user)
@@ -66,7 +65,6 @@ func TestJoins(t *testing.T) {
6665
}
6766

6867
func TestJoinsForSlice(t *testing.T) {
69-
t.Skip()
7068
users := []User{
7169
*GetUser("slice-joins-1", Config{Company: true, Manager: true, Account: true}),
7270
*GetUser("slice-joins-2", Config{Company: true, Manager: true, Account: true}),
@@ -101,8 +99,6 @@ func TestJoinsForSlice(t *testing.T) {
10199
}
102100

103101
func TestJoinConds(t *testing.T) {
104-
t.Skip()
105-
106102
user := *GetUser("joins-conds", Config{Account: true, Pets: 3})
107103
DB.Save(&user)
108104

@@ -157,8 +153,6 @@ func TestJoinConds(t *testing.T) {
157153
}
158154

159155
func TestJoinOn(t *testing.T) {
160-
t.Skip()
161-
162156
user := *GetUser("joins-on", Config{Pets: 2})
163157
DB.Save(&user)
164158

@@ -281,8 +275,6 @@ func TestJoinWithSoftDeleted(t *testing.T) {
281275
}
282276

283277
func TestInnerJoins(t *testing.T) {
284-
t.Skip()
285-
286278
user := *GetUser("inner-joins-1", Config{Company: true, Manager: true, Account: true, NamedPet: false})
287279

288280
DB.Create(&user)
@@ -336,8 +328,6 @@ func TestJoinWithSameColumnName(t *testing.T) {
336328
}
337329

338330
func TestJoinArgsWithDB(t *testing.T) {
339-
t.Skip()
340-
341331
user := *GetUser("joins-args-db", Config{Pets: 2})
342332
DB.Save(&user)
343333

tests/passed-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ TestHooksForSlice
142142
TestFailedToSaveAssociationShouldRollback
143143
TestUpdateCallbacks
144144
TestPropagateUnscoped
145-
#TestOverrideJoinTable
145+
TestOverrideJoinTable
146146
TestJoins
147147
TestJoinsForSlice
148148
TestJoinConds

0 commit comments

Comments
 (0)