From 24372776e16b3c1c3e054726b709c65026cca17c Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 22 Dec 2010 11:45:37 +0000 Subject: [PATCH] Test to verify that #2189 (count with has_many :through and a named_scope) is fixed --- .../has_many_through_associations_test.rb | 11 +++++++++-- activerecord/test/models/category.rb | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) 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 94e1eb8..adcb149 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -17,11 +17,13 @@ require 'models/developer' require 'models/subscriber' require 'models/book' require 'models/subscription' +require 'models/category' +require 'models/categorization' class HasManyThroughAssociationsTest < ActiveRecord::TestCase - fixtures :posts, :readers, :people, :comments, :authors, + fixtures :posts, :readers, :people, :comments, :authors, :categories, :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 @@ -456,4 +458,9 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase post.people << people(:michael) assert_equal readers + 1, post.readers.size end + + def test_count_has_many_through_with_named_scope + assert_equal 2, authors(:mary).categories.count + assert_equal 1, authors(:mary).categories.general.count + end end diff --git a/activerecord/test/models/category.rb b/activerecord/test/models/category.rb index 4841584..06908ea 100644 --- a/activerecord/test/models/category.rb +++ b/activerecord/test/models/category.rb @@ -23,6 +23,8 @@ class Category < ActiveRecord::Base has_many :categorizations has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id' + + scope :general, :conditions => { :name => 'General' } end class SpecialCategory < Category -- 1.7.1