Skip to content

Commit

Permalink
Coerce tests that rely on upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan committed Sep 21, 2023
1 parent c3fab52 commit 6bd5d83
Showing 1 changed file with 21 additions and 47 deletions.
68 changes: 21 additions & 47 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2362,55 +2362,37 @@ def test_invalid_encoding_query_coerced
end
end

# SQL Server does not support upsert yet
# TODO: Remove coerce after Rails 7.1.0 (see https://github.com/rails/rails/pull/44050)
class InsertAllTest < ActiveRecord::TestCase
coerce_tests! :test_upsert_all_only_updates_the_column_provided_via_update_only
def test_upsert_all_only_updates_the_column_provided_via_update_only_coerced
assert_raises(ArgumentError, /does not support upsert/) do
original_test_upsert_all_only_updates_the_column_provided_via_update_only
end
end

coerce_tests! :test_upsert_all_only_updates_the_list_of_columns_provided_via_update_only
def test_upsert_all_only_updates_the_list_of_columns_provided_via_update_only_coerced
assert_raises(ArgumentError, /does not support upsert/) do
original_test_upsert_all_only_updates_the_list_of_columns_provided_via_update_only
end
end

coerce_tests! :test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_true
def test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_true_coerced
assert_raises(ArgumentError, /does not support upsert/) do
original_test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_true
end
end
# Same as original but using INSERTED.name as UPPER argument
coerce_tests! :test_insert_all_returns_requested_sql_fields
def test_insert_all_returns_requested_sql_fields_coerced
skip unless supports_insert_returning?

coerce_tests! :test_upsert_all_respects_created_at_precision_when_touched_implicitly
def test_upsert_all_respects_created_at_precision_when_touched_implicitly_coerced
assert_raises(ArgumentError, /does not support upsert/) do
original_test_upsert_all_respects_created_at_precision_when_touched_implicitly
end
result = Book.insert_all! [{ name: "Rework", author_id: 1 }], returning: Arel.sql("UPPER(INSERTED.name) as name")
assert_equal %w[ REWORK ], result.pluck("name")
end

coerce_tests! :test_upsert_all_does_not_implicitly_set_timestamps_on_create_when_model_record_timestamps_is_true_but_overridden
def test_upsert_all_does_not_implicitly_set_timestamps_on_create_when_model_record_timestamps_is_true_but_overridden_coerced
# SQL Server does not support upsert. Coerce can be removed after https://github.com/rails/rails/pull/49344
coerce_tests! :test_insert_all_should_handle_empty_arrays
def test_insert_all_should_handle_empty_arrays_coerced
assert_raises(ArgumentError, /does not support upsert/) do
original_test_upsert_all_does_not_implicitly_set_timestamps_on_create_when_model_record_timestamps_is_true_but_overridden
original_test_insert_all_should_handle_empty_arrays
end
end

coerce_tests! :test_upsert_all_does_not_implicitly_set_timestamps_on_create_when_model_record_timestamps_is_false
def test_upsert_all_does_not_implicitly_set_timestamps_on_create_when_model_record_timestamps_is_false_coerced
# SQL Server does not support upsert. Coerce can be removed after https://github.com/rails/rails/pull/49344
coerce_tests! :test_insert_all_and_upsert_all_with_aliased_attributes
def test_insert_all_and_upsert_all_with_aliased_attributes_coerced
assert_raises(ArgumentError, /does not support upsert/) do
original_test_upsert_all_does_not_implicitly_set_timestamps_on_create_when_model_record_timestamps_is_false
original_test_insert_all_and_upsert_all_with_aliased_attributes
end
end

coerce_tests! :test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_false_but_overridden
def test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_false_but_overridden_coerced
# SQL Server does not support upsert. Coerce can be removed after https://github.com/rails/rails/pull/49344
coerce_tests! :test_insert_all_and_upsert_all_with_sti
def test_insert_all_and_upsert_all_with_sti_coerced
assert_raises(ArgumentError, /does not support upsert/) do
original_test_upsert_all_implicitly_sets_timestamps_on_create_when_model_record_timestamps_is_false_but_overridden
original_test_insert_all_and_upsert_all_with_sti
end
end
end
Expand All @@ -2434,17 +2416,6 @@ def test_disable_joins_through_with_enum_type_coerced
end
end

class InsertAllTest < ActiveRecord::TestCase
coerce_tests! :test_insert_all_returns_requested_sql_fields
# Same as original but using INSERTED.name as UPPER argument
def test_insert_all_returns_requested_sql_fields_coerced
skip unless supports_insert_returning?

result = Book.insert_all! [{ name: "Rework", author_id: 1 }], returning: Arel.sql("UPPER(INSERTED.name) as name")
assert_equal %w[ REWORK ], result.pluck("name")
end
end

class ActiveRecord::Encryption::EncryptableRecordTest < ActiveRecord::EncryptionTestCase
# TODO: Remove coerce after Rails 7.1.0 (see https://github.com/rails/rails/pull/44052)
# Same as original but SQL Server string is varchar(4000), not varchar(255) as other adapters. Produce invalid strings with 4001 characters
Expand All @@ -2455,4 +2426,7 @@ class ActiveRecord::Encryption::EncryptableRecordTest < ActiveRecord::Encryption
author = EncryptedAuthor.create(name: "a" * 4001)
assert_not author.valid?
end

# SQL Server does not support upsert. Coerce can be removed after https://github.com/rails/rails/pull/49344
coerce_tests! %r{loading records with encrypted attributes defined on columns with default values}
end

0 comments on commit 6bd5d83

Please sign in to comment.