Permalink
Browse files

added a failing test case for counting has_many :through associations…

… with scopes

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent 34c3162 commit a92790ab862790acc627a3194770da37e400d64b @ianterrell ianterrell committed with NZKoz Mar 17, 2009
Showing with 10 additions and 1 deletion.
  1. +8 −1 activerecord/test/cases/calculations_test.rb
  2. +2 −0 activerecord/test/models/toy.rb
@@ -2,6 +2,9 @@
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)
@@ -284,6 +287,10 @@ 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
@@ -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

0 comments on commit a92790a

Please sign in to comment.