File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,16 @@ def test_insert_all_with_skip_duplicates_and_autonumber_id_given
185
185
end
186
186
end
187
187
188
+ def test_insert_all_only_applies_last_value_when_given_duplicate_identifiers
189
+ skip unless supports_insert_on_duplicate_skip?
190
+
191
+ Book . insert_all [
192
+ { id : 111 , name : "expected_new_name" } ,
193
+ { id : 111 , name : "unexpected_new_name" }
194
+ ]
195
+ assert_equal "expected_new_name" , Book . find ( 111 ) . name
196
+ end
197
+
188
198
def test_skip_duplicates_strategy_does_not_secretly_upsert
189
199
skip unless supports_insert_on_duplicate_skip?
190
200
@@ -399,6 +409,18 @@ def test_upsert_all_updates_existing_record_by_primary_key
399
409
assert_equal "New edition" , Book . find ( 1 ) . name
400
410
end
401
411
412
+ def test_upsert_all_only_applies_last_value_when_given_duplicate_identifiers
413
+ skip unless supports_insert_on_duplicate_update? && !current_adapter? ( :PostgreSQLAdapter )
414
+
415
+ Book . create! ( id : 112 , name : "original_name" )
416
+
417
+ Book . upsert_all [
418
+ { id : 112 , name : "unexpected_new_name" } ,
419
+ { id : 112 , name : "expected_new_name" }
420
+ ]
421
+ assert_equal "expected_new_name" , Book . find ( 112 ) . name
422
+ end
423
+
402
424
def test_upsert_all_does_notupdates_existing_record_by_when_there_is_no_key
403
425
skip unless supports_insert_on_duplicate_update? && !supports_insert_conflict_target?
404
426
You can’t perform that action at this time.
0 commit comments