|
37 | 37 | require "models/sharded/blog"
|
38 | 38 | require "models/sharded/blog_post"
|
39 | 39 | require "models/sharded/comment"
|
| 40 | +require "models/member_detail" |
| 41 | +require "models/organization" |
40 | 42 |
|
41 | 43 |
|
42 | 44 | class AssociationsTest < ActiveRecord::TestCase
|
@@ -539,8 +541,8 @@ def test_associations_raise_with_name_error_if_associated_to_classes_that_do_not
|
539 | 541 | end
|
540 | 542 |
|
541 | 543 | class PreloaderTest < ActiveRecord::TestCase
|
542 |
| - fixtures :posts, :comments, :books, :authors, :tags, :taggings, :essays, :categories, |
543 |
| - :author_addresses, :sharded_blog_posts, :sharded_comments |
| 544 | + fixtures :posts, :comments, :books, :authors, :tags, :taggings, :essays, :categories, :author_addresses, |
| 545 | + :sharded_blog_posts, :sharded_comments, :members, :member_details, :organizations |
544 | 546 |
|
545 | 547 | def test_preload_with_scope
|
546 | 548 | post = posts(:welcome)
|
@@ -629,6 +631,21 @@ def test_preload_grouped_queries_of_through_records
|
629 | 631 | end
|
630 | 632 | end
|
631 | 633 |
|
| 634 | + def test_preload_through_records_with_already_loaded_middle_record |
| 635 | + member = members(:groucho) |
| 636 | + expected_member_detail_ids = member.organization_member_details_2.pluck(:id) |
| 637 | + |
| 638 | + member.reload.organization # load through record |
| 639 | + |
| 640 | + assert_queries(1) do |
| 641 | + ActiveRecord::Associations::Preloader.new(records: [member], associations: :organization_member_details_2).call |
| 642 | + end |
| 643 | + |
| 644 | + assert_no_queries do |
| 645 | + assert_equal expected_member_detail_ids.sort, member.organization_member_details_2.map(&:id).sort |
| 646 | + end |
| 647 | + end |
| 648 | + |
632 | 649 | def test_preload_with_instance_dependent_scope
|
633 | 650 | david = authors(:david)
|
634 | 651 | david2 = Author.create!(name: "David")
|
|
0 commit comments