aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-12-16 00:40:03 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-15 17:47:42 -0800
commit09ddca67acbb88e2fdd7300670839cbf647b2694 (patch)
treec0be01dd066c966daaf76e35be91e41567f6cb96 /activerecord/test/cases
parent6bfa846a2cc950bbb3d8b30f076589a60f38b821 (diff)
downloadrails-09ddca67acbb88e2fdd7300670839cbf647b2694.tar.gz
rails-09ddca67acbb88e2fdd7300670839cbf647b2694.tar.bz2
rails-09ddca67acbb88e2fdd7300670839cbf647b2694.zip
Fix problem with duplicated records when a :uniq :through association is preloaded [#2447 state:resolved]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb9
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb8
2 files changed, 15 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 34a1cdeebe..d5262b1ee4 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -20,10 +20,11 @@ require 'models/project'
require 'models/member'
require 'models/membership'
require 'models/club'
+require 'models/categorization'
class EagerAssociationTest < ActiveRecord::TestCase
fixtures :posts, :comments, :authors, :author_addresses, :categories, :categories_posts,
- :companies, :accounts, :tags, :taggings, :people, :readers,
+ :companies, :accounts, :tags, :taggings, :people, :readers, :categorizations,
:owners, :pets, :author_favorites, :jobs, :references, :subscribers, :subscriptions, :books,
:developers, :projects, :developers_projects, :members, :memberships, :clubs
@@ -910,4 +911,10 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_queries(2) { @tagging = Tagging.preload(:taggable).find(t.id) }
assert_no_queries { assert ! @tagging.taggable }
end
+
+ def test_preloading_has_many_through_with_uniq
+ mary = Author.includes(:unique_categorized_posts).where(:id => authors(:mary).id).first
+ assert_equal 1, mary.unique_categorized_posts.length
+ assert_equal 1, mary.unique_categorized_post_ids.length
+ end
end
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 44ff01ddc0..77bc369ecc 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -23,7 +23,7 @@ require 'models/category'
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :posts, :readers, :people, :comments, :authors,
:owners, :pets, :toys, :jobs, :references, :companies,
- :subscribers, :books, :subscriptions, :developers
+ :subscribers, :books, :subscriptions, :developers, :categorizations
# Dummies to force column loads so query counts are clean.
def setup
@@ -473,4 +473,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
category = authors(:david).special_categories.create(:name => "Foo")
assert_equal 1, category.categorizations.where(:special => true).count
end
+
+ def test_joining_has_many_through_with_uniq
+ mary = Author.joins(:unique_categorized_posts).where(:id => authors(:mary).id).first
+ assert_equal 1, mary.unique_categorized_posts.length
+ assert_equal 1, mary.unique_categorized_post_ids.length
+ end
end