Skip to content

Commit

Permalink
Add tests guarding against regressions identified in rails/rails@640e…
Browse files Browse the repository at this point in the history
…3981

We had to revert rails/rails@6dd1929 due to some regressions it caused. Here are some tests that would prevent those regressions in the future. See previous commits for more detail.
  • Loading branch information
andrewn617 committed Mar 26, 2024
1 parent 12dbb80 commit 62f9790
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions activerecord/test/cases/table_metadata_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "cases/helper"
require "models/developer"

module ActiveRecord
class TableMetadataTest < ActiveSupport::TestCase
test "#associated_table creates the right type caster for joined table with different association name" do
base_table_metadata = TableMetadata.new(AuditRequiredDeveloper, Arel::Table.new("developers"))

associated_table_metadata = base_table_metadata.associated_table("audit_logs")

assert_equal ActiveRecord::Type::String, associated_table_metadata.arel_table.type_for_attribute(:message).class
end
end
end
19 changes: 19 additions & 0 deletions activerecord/test/cases/type_caster/connection_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "cases/helper"
require "models/developer"

module ActiveRecord
module TypeCaster
class ConnectionTest < ActiveSupport::TestCase
test "#type_for_attribute is not aware of custom types" do
type_caster = Connection.new(AttributedDeveloper, "developers")

type = type_caster.type_for_attribute(:name)

assert_not_equal DeveloperName, type.class
assert_equal ActiveRecord::Type::String, type.class
end
end
end
end
5 changes: 5 additions & 0 deletions activerecord/test/models/developer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,8 @@ class ColumnNamesCachedDeveloper < ActiveRecord::Base
self.table_name = "developers"
self.ignored_columns += ["name"] if column_names.include?("name")
end

class AuditRequiredDeveloper < ActiveRecord::Base
self.table_name = "developers"
has_many :required_audit_logs, class_name: "AuditLogRequired"
end

0 comments on commit 62f9790

Please sign in to comment.