Skip to content

Commit

Permalink
Test to verify that #2189 (count with has_many :through and a named_s…
Browse files Browse the repository at this point in the history
…cope) is fixed [#2189 state:resolved]
  • Loading branch information
jonleighton committed Dec 23, 2010
1 parent bbb2252 commit 90f55bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -17,11 +17,13 @@
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
Expand Down Expand Up @@ -456,4 +458,9 @@ def test_size_of_through_association_should_increase_correctly_when_has_many_ass
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
2 changes: 2 additions & 0 deletions activerecord/test/models/category.rb
Expand Up @@ -23,6 +23,8 @@ def self.what_are_you

has_many :categorizations
has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'

scope :general, :conditions => { :name => 'General' }
end

class SpecialCategory < Category
Expand Down

0 comments on commit 90f55bd

Please sign in to comment.