Skip to content

Coerce tests to check for subclasses rather than actual classes #1180

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
May 19, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2653,3 +2653,34 @@ def test_url_invalid_adapter_coerced
end
end
end

module ActiveRecord
class TableMetadataTest < ActiveSupport::TestCase
# Adapter returns an object that is subclass of what is expected in the original test.
coerce_tests! %r{#associated_table creates the right type caster for joined table with different association name}
def associated_table_creates_the_right_type_caster_for_joined_table_with_different_association_name_coerced
base_table_metadata = TableMetadata.new(AuditRequiredDeveloper, Arel::Table.new("developers"))

associated_table_metadata = base_table_metadata.associated_table("audit_logs")

assert associated_table_metadata.arel_table.type_for_attribute(:message).is_a?(ActiveRecord::Type::String)
end
end
end

module ActiveRecord
module TypeCaster
class ConnectionTest < ActiveSupport::TestCase
# Adapter returns an object that is subclass of what is expected in the original test.
coerce_tests! %r{#type_for_attribute is not aware of custom types}
def type_for_attribute_is_not_aware_of_custom_types_coerced
type_caster = Connection.new(AttributedDeveloper, "developers")

type = type_caster.type_for_attribute(:name)

assert_not_equal DeveloperName, type.class
assert type.is_a?(ActiveRecord::Type::String)
end
end
end
end
9 changes: 7 additions & 2 deletions test/cases/helper_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
require "support/query_assertions"
require "mocha/minitest"

module ActiveSupport
class TestCase < ::Minitest::Test
include ARTest::SQLServer::CoerceableTest
end
end

module ActiveRecord
class TestCase < ActiveSupport::TestCase
SQLServer = ActiveRecord::ConnectionAdapters::SQLServer

include ARTest::SQLServer::CoerceableTest,
ARTest::SQLServer::ConnectionReflection,
include ARTest::SQLServer::ConnectionReflection,
ActiveSupport::Testing::Stream,
ARTest::SQLServer::QueryAssertions

Expand Down