Merge pull request #9872 from senny/test_case_to_prevent_unnecessary_reset

test-case to prevent resetting associations when preloading twice.
This commit is contained in:
Jon Leighton 2013-03-22 07:24:51 -07:00
commit d8d6dada77
1 changed files with 7 additions and 0 deletions

View File

@ -1174,6 +1174,13 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_no_queries { assert_equal 5, author.posts.size, "should not cache a subset of the association" } assert_no_queries { assert_equal 5, author.posts.size, "should not cache a subset of the association" }
end end
test "preloading a through association twice does not reset it" do
members = Member.includes(current_membership: :club).includes(:club).to_a
assert_no_queries {
assert_equal 3, members.map(&:current_membership).map(&:club).size
}
end
test "works in combination with order(:symbol)" do test "works in combination with order(:symbol)" do
author = Author.includes(:posts).references(:posts).order(:name).where('posts.title IS NOT NULL').first author = Author.includes(:posts).references(:posts).order(:name).where('posts.title IS NOT NULL').first
assert_equal authors(:bob), author assert_equal authors(:bob), author