From 0b7571d0a7a811c21a69f08b6c08c7d7ead374c3 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Mon, 21 Oct 2024 13:49:56 +0100 Subject: [PATCH 1/2] Fix tests --- test/cases/coerced_tests.rb | 41 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/test/cases/coerced_tests.rb b/test/cases/coerced_tests.rb index 9ad625757..982e682fc 100644 --- a/test/cases/coerced_tests.rb +++ b/test/cases/coerced_tests.rb @@ -1341,6 +1341,14 @@ def test_registering_new_handlers_for_association_coerced assert_match %r{#{Regexp.escape(topic_title)} ~ N'rails'}i, Reply.joins(:topic).where(topics: { title: /rails/ }).to_sql end + # Same as original test except string has `N` prefix to indicate unicode string. + coerce_tests! :test_registering_new_handlers_for_joins_coerced + def test_registering_new_handlers_for_joins_coerced + Reply.belongs_to :regexp_topic, -> { where(title: /rails/) }, class_name: "Topic", foreign_key: "parent_id" + + assert_match %r{#{Regexp.escape(quote_table_name("regexp_topic.title"))} ~ N'rails'}i, Reply.joins(:regexp_topic).references(Arel.sql("regexp_topic")).to_sql + end + private def topic_title @@ -2177,17 +2185,6 @@ class EnumTest < ActiveRecord::TestCase Book.lease_connection.add_index(:books, [:author_id, :name], unique: true) end - # Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite. - coerce_tests! %r{declare multiple enums at a time} - test "declare multiple enums at a time coerced" do - Book.lease_connection.remove_index(:books, column: [:author_id, :name]) - - send(:'original_declare multiple enums at a time') - ensure - Book.where(author_id: nil, name: nil).delete_all - Book.lease_connection.add_index(:books, [:author_id, :name], unique: true) - end - # Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite. coerce_tests! %r{serializable\? with large number label} test "serializable? with large number label coerced" do @@ -2669,6 +2666,28 @@ def test_url_invalid_adapter_coerced end end +module ActiveRecord + module ConnectionAdapters + class RegistrationIsolatedTest < ActiveRecord::TestCase + # SQL Server was not included in the list of available adapters in the error message. + coerce_tests! %r{resolve raises if the adapter is using the pre 7.2 adapter registration API} + def resolve_raises_if_the_adapter_is_using_the_pre_7_2_adapter_registration_API + exception = assert_raises(ActiveRecord::AdapterNotFound) do + ActiveRecord::ConnectionAdapters.resolve("fake_legacy") + end + + assert_equal( + "Database configuration specifies nonexistent 'ridiculous' adapter. Available adapters are: abstract, fake, mysql2, postgresql, sqlite3, sqlserver, trilogy. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile if it's not in the list of available adapters.", + exception.message + ) + ensure + ActiveRecord::ConnectionAdapters.instance_variable_get(:@adapters).delete("fake_legacy") + end + end + end +end + + module ActiveRecord class TableMetadataTest < ActiveSupport::TestCase # Adapter returns an object that is subclass of what is expected in the original test. From f8a0f0bbdf9f05e1e03a8141c1ace44af8352132 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Mon, 21 Oct 2024 13:56:06 +0100 Subject: [PATCH 2/2] Update coerced_tests.rb --- test/cases/coerced_tests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cases/coerced_tests.rb b/test/cases/coerced_tests.rb index 982e682fc..1ffa0694c 100644 --- a/test/cases/coerced_tests.rb +++ b/test/cases/coerced_tests.rb @@ -1342,7 +1342,7 @@ def test_registering_new_handlers_for_association_coerced end # Same as original test except string has `N` prefix to indicate unicode string. - coerce_tests! :test_registering_new_handlers_for_joins_coerced + coerce_tests! :test_registering_new_handlers_for_joins def test_registering_new_handlers_for_joins_coerced Reply.belongs_to :regexp_topic, -> { where(title: /rails/) }, class_name: "Topic", foreign_key: "parent_id"