From 8fa4c57d46b03a705c2c665dd2b58c0f4d172793 Mon Sep 17 00:00:00 2001 From: Ian Terrell Date: Tue, 17 Mar 2009 12:08:47 -0400 Subject: [PATCH] added a failing test case for counting has_many :through associations with scopes --- activerecord/test/cases/calculations_test.rb | 11 +++++++++-- activerecord/test/models/toy.rb | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 56dcdea..6d3b8e6 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -2,6 +2,9 @@ require "cases/helper" require 'models/company' require 'models/topic' require 'models/edge' +require 'models/owner' +require 'models/pet' +require 'models/toy' Company.has_many :accounts @@ -10,7 +13,7 @@ class NumericData < ActiveRecord::Base end class CalculationsTest < ActiveRecord::TestCase - fixtures :companies, :accounts, :topics + fixtures :companies, :accounts, :topics, :owners, :pets, :toys def test_should_sum_field assert_equal 318, Account.sum(:credit_limit) @@ -296,7 +299,11 @@ class CalculationsTest < ActiveRecord::TestCase def test_count_with_too_many_parameters_raises assert_raise(ArgumentError) { Account.count(1, 2, 3) } end - + + def test_count_with_scoped_has_many_through_association + assert_equal 1, owners(:blackbeard).toys.with_name('bone').count + end + def test_should_sum_expression assert_equal '636', Account.sum("2 * credit_limit") end diff --git a/activerecord/test/models/toy.rb b/activerecord/test/models/toy.rb index 79a88db..9635e19 100644 --- a/activerecord/test/models/toy.rb +++ b/activerecord/test/models/toy.rb @@ -1,4 +1,6 @@ class Toy < ActiveRecord::Base set_primary_key :toy_id belongs_to :pet + + named_scope :with_name, lambda { |name| {:conditions => {:name => name}} } end -- 1.6.0.2