Skip to content

Commit cd5fe84

Browse files
committed
Add tests guarding against regressions identified in rails/rails@640e3981
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.
1 parent 12dbb80 commit cd5fe84

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
require "cases/helper"
4+
require "models/developer"
5+
6+
module ActiveRecord
7+
class TableMetadataTest < ActiveSupport::TestCase
8+
test "#associated_table creates the right type caster for joined table with different association name" do
9+
base_table_metadata = TableMetadata.new(AuditRequiredDeveloper, Arel::Table.new("developers"))
10+
11+
associated_table_metadata = base_table_metadata.associated_table("audit_logs")
12+
13+
assert_equal ActiveRecord::Type::String, associated_table_metadata.arel_table.type_for_attribute(:message).class
14+
end
15+
end
16+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "cases/helper"
4+
require "models/developer"
5+
6+
module ActiveRecord
7+
module TypeCaster
8+
class ConnectionTest < ActiveSupport::TestCase
9+
test "#type_for_attribute is not aware of custom types" do
10+
type_caster = Connection.new(AttributedDeveloper, "developers")
11+
12+
type = type_caster.type_for_attribute(:name)
13+
14+
assert_not_equal DeveloperName, type.class
15+
assert_equal ActiveRecord::Type::String, type.class
16+
end
17+
end
18+
end
19+
end

activerecord/test/models/developer.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,8 @@ class ColumnNamesCachedDeveloper < ActiveRecord::Base
372372
self.table_name = "developers"
373373
self.ignored_columns += ["name"] if column_names.include?("name")
374374
end
375+
376+
class AuditRequiredDeveloper < ActiveRecord::Base
377+
self.table_name = "developers"
378+
has_many :required_audit_logs, class_name: "AuditLogRequired"
379+
end

0 commit comments

Comments
 (0)