Skip to content

Fix tests for Rails 8.0.0.rc1 #1252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading