Skip to content

Commit d39ea2b

Browse files
authored
Merge pull request rails#49344 from aidanharan/skip-tests-unless-supports-insert-on-duplicate-update
Skip unless adapter supports insert on duplicate update
2 parents 26d24d6 + 4381416 commit d39ea2b

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

activerecord/test/cases/encryption/encryptable_record_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ def name
298298
end
299299

300300
test "loading records with encrypted attributes defined on columns with default values" do
301+
skip unless supports_insert_on_duplicate_update?
302+
301303
EncryptedBook.insert({ format: "ebook" })
302304
book = EncryptedBook.last
303305
assert_equal "<untitled>", book.name

activerecord/test/cases/insert_all_test.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def test_insert_all
6464
end
6565

6666
def test_insert_all_should_handle_empty_arrays
67+
skip unless supports_insert_on_duplicate_update?
68+
6769
assert_empty Book.insert_all([])
6870
assert_empty Book.insert_all!([])
6971
assert_empty Book.upsert_all([])
@@ -277,25 +279,27 @@ def test_insert_all_logs_message_including_model_name
277279
end
278280

279281
def test_insert_all_and_upsert_all_with_aliased_attributes
282+
skip unless supports_insert_on_duplicate_update?
283+
280284
if supports_insert_returning?
281285
assert_difference "Book.count" do
282286
result = Book.insert_all [{ title: "Remote", author_id: 1 }], returning: :title
283287
assert_includes result.columns, "title"
284288
end
285289
end
286290

287-
if supports_insert_on_duplicate_update?
288-
Book.upsert_all [{ id: 101, title: "Perelandra", author_id: 7, isbn: "1974522598" }]
289-
Book.upsert_all [{ id: 101, title: "Perelandra 2", author_id: 6, isbn: "111111" }], update_only: %i[ title isbn ]
291+
Book.upsert_all [{ id: 101, title: "Perelandra", author_id: 7, isbn: "1974522598" }]
292+
Book.upsert_all [{ id: 101, title: "Perelandra 2", author_id: 6, isbn: "111111" }], update_only: %i[ title isbn ]
290293

291-
book = Book.find(101)
292-
assert_equal "Perelandra 2", book.title, "Should have updated the title"
293-
assert_equal "111111", book.isbn, "Should have updated the isbn"
294-
assert_equal 7, book.author_id, "Should not have updated the author_id"
295-
end
294+
book = Book.find(101)
295+
assert_equal "Perelandra 2", book.title, "Should have updated the title"
296+
assert_equal "111111", book.isbn, "Should have updated the isbn"
297+
assert_equal 7, book.author_id, "Should not have updated the author_id"
296298
end
297299

298300
def test_insert_all_and_upsert_all_with_sti
301+
skip unless supports_insert_on_duplicate_update?
302+
299303
assert_difference -> { Category.count }, 2 do
300304
SpecialCategory.insert_all [{ name: "First" }, { name: "Second", type: nil }]
301305
end
@@ -304,15 +308,13 @@ def test_insert_all_and_upsert_all_with_sti
304308
assert_equal "SpecialCategory", first.type
305309
assert_nil second.type
306310

307-
if supports_insert_on_duplicate_update?
308-
SpecialCategory.upsert_all [{ id: 103, name: "First" }, { id: 104, name: "Second", type: nil }]
311+
SpecialCategory.upsert_all [{ id: 103, name: "First" }, { id: 104, name: "Second", type: nil }]
309312

310-
category3 = Category.find(103)
311-
assert_equal "SpecialCategory", category3.type
313+
category3 = Category.find(103)
314+
assert_equal "SpecialCategory", category3.type
312315

313-
category4 = Category.find(104)
314-
assert_nil category4.type
315-
end
316+
category4 = Category.find(104)
317+
assert_nil category4.type
316318
end
317319

318320
def test_upsert_logs_message_including_model_name

0 commit comments

Comments
 (0)