From 92a5cd38650fe6f54f86bb29d9f28e49943d03a9 Mon Sep 17 00:00:00 2001 From: Arya Asemanfar Date: Sun, 17 Jan 2010 00:53:35 -0800 Subject: [PATCH 2/2] added test case for double loading associations --- .../cases/double_loading_included_associations.rb | 43 ++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) create mode 100644 activerecord/test/cases/double_loading_included_associations.rb diff --git a/activerecord/test/cases/double_loading_included_associations.rb b/activerecord/test/cases/double_loading_included_associations.rb new file mode 100644 index 0000000..b9abaae --- /dev/null +++ b/activerecord/test/cases/double_loading_included_associations.rb @@ -0,0 +1,43 @@ +require "cases/helper" + +class DoubleLoadingIncludedAssociationsAuthor < ActiveRecord::Base + self.table_name = "authors" + has_many :posts, :include => [:comments], :class_name => 'DoubleLoadingIncludedAssociationsPost', :foreign_key => "author_id" + +end + +class DoubleLoadingIncludedAssociationsPost < ActiveRecord::Base + self.table_name = "posts" + has_many :comments, :class_name => 'DoubleLoadingIncludedAssociationsComment', :foreign_key => "post_id" + def after_initialize + if self.id == 2 + self.comments.to_a + end + end + + def self.inheritance_column + "unused_type" + end +end + +class DoubleLoadingIncludedAssociationsComment < ActiveRecord::Base + self.table_name = "comments" + + def self.inheritance_column + "unused_type" + end +end + + +class DoubleLoadingIncludedAssociations < ActiveRecord::TestCase + fixtures :authors, :posts, :comments + + def test_doesnt_double_loads_associations + david = DoubleLoadingIncludedAssociationsAuthor.find(1) + david.posts.to_a + has_no_duplicates = david.posts.all? do |post| + post.comments.size == post.comments.uniq.size + end + assert has_no_duplicates + end +end -- 1.6.3.2