From df7b74668ebc0ae9978d4c27125db7fec730b110 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 19 Apr 2006 21:37:54 +0000 Subject: Fix the HasManyAssociation#count method so it uses the new ActiveRecord::Base#count syntax, while maintaining backwards compatibility. [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4237 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 20 ++++++++++++++++++-- activerecord/test/fixtures/company.rb | 1 + activerecord/test/reflection_test.rb | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 173808c370..f94908ced1 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -283,10 +283,26 @@ class HasManyAssociationsTest < Test::Unit::TestCase companies(:first_firm).clients_of_firm.each {|f| } end - def test_counting + def test_counting_with_counter_sql assert_equal 2, Firm.find(:first).clients.count end - + + def test_counting + assert_equal 2, Firm.find(:first).plain_clients.count + end + + def test_counting_with_single_conditions + assert_equal 2, Firm.find(:first).plain_clients.count('1=1') + end + + def test_counting_with_single_hash + assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => '1=1') + end + + def test_counting_with_column_name_and_hash + assert_equal 2, Firm.find(:first).plain_clients.count(:all, :conditions => '1=1') + end + def test_finding assert_equal 2, Firm.find(:first).clients.length end diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 59a7cdd13e..526748784e 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -28,6 +28,7 @@ class Firm < Company has_many :no_clients_using_counter_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000', :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000' + has_many :plain_clients, :class_name => 'Client' has_one :account, :foreign_key => "firm_id", :dependent => :destroy end diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb index 64689595fe..4882ca246f 100644 --- a/activerecord/test/reflection_test.rb +++ b/activerecord/test/reflection_test.rb @@ -137,8 +137,8 @@ class ReflectionTest < Test::Unit::TestCase end def test_reflection_of_all_associations - assert_equal 13, Firm.reflect_on_all_associations.size - assert_equal 11, Firm.reflect_on_all_associations(:has_many).size + assert_equal 14, Firm.reflect_on_all_associations.size + assert_equal 12, Firm.reflect_on_all_associations(:has_many).size assert_equal 2, Firm.reflect_on_all_associations(:has_one).size assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size end -- cgit v1.2.3