|
39 | 39 | require "models/cpk"
|
40 | 40 | require "models/member_detail"
|
41 | 41 | require "models/organization"
|
| 42 | +require "models/dog" |
| 43 | +require "models/other_dog" |
42 | 44 |
|
43 | 45 |
|
44 | 46 | class AssociationsTest < ActiveRecord::TestCase
|
@@ -773,7 +775,8 @@ def test_associations_raise_with_name_error_if_associated_to_classes_that_do_not
|
773 | 775 | class PreloaderTest < ActiveRecord::TestCase
|
774 | 776 | fixtures :posts, :comments, :books, :authors, :tags, :taggings, :essays, :categories, :author_addresses,
|
775 | 777 | :sharded_blog_posts, :sharded_comments, :sharded_blog_posts_tags, :sharded_tags,
|
776 |
| - :members, :member_details, :organizations, :cpk_orders, :cpk_order_agreements |
| 778 | + :members, :member_details, :organizations, :cpk_orders, :cpk_order_agreements, |
| 779 | + :dogs, :other_dogs |
777 | 780 |
|
778 | 781 | def test_preload_with_scope
|
779 | 782 | post = posts(:welcome)
|
@@ -1206,6 +1209,23 @@ def test_preload_does_not_group_same_scope_different_key_name
|
1206 | 1209 | end
|
1207 | 1210 | end
|
1208 | 1211 |
|
| 1212 | + def test_multi_database_polymorphic_preload_with_same_table_name |
| 1213 | + dog = dogs(:sophie) |
| 1214 | + dog_comment = comments(:greetings) |
| 1215 | + dog_comment.origin_type = dog.class.name |
| 1216 | + dog_comment.origin_id = dog.id |
| 1217 | + |
| 1218 | + other_dog = other_dogs(:lassie) |
| 1219 | + other_dog_comment = comments(:more_greetings) |
| 1220 | + other_dog_comment.origin_type = other_dog.class.name |
| 1221 | + other_dog_comment.origin_id = other_dog.id |
| 1222 | + |
| 1223 | + assert_queries(2) do |
| 1224 | + preloader = ActiveRecord::Associations::Preloader.new(records: [dog_comment, other_dog_comment], associations: :origin) |
| 1225 | + preloader.call |
| 1226 | + end |
| 1227 | + end |
| 1228 | + |
1209 | 1229 | def test_preload_with_available_records
|
1210 | 1230 | post = posts(:welcome)
|
1211 | 1231 | david = authors(:david)
|
|
0 commit comments