diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-07 06:29:31 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-07 06:29:31 +0000 |
commit | 7b37c779d805081aedb635a8bc801aa4a4339cc2 (patch) | |
tree | 4f158d402df6ede6085bbced53a108447e7fd07f /activerecord/test | |
parent | 4ab40059b7925f35cddb0f76dba27ea6cd018de7 (diff) | |
download | rails-7b37c779d805081aedb635a8bc801aa4a4339cc2.tar.gz rails-7b37c779d805081aedb635a8bc801aa4a4339cc2.tar.bz2 rails-7b37c779d805081aedb635a8bc801aa4a4339cc2.zip |
Fixed counter_sql when no records exist in database for PostgreSQL (would give error, not 0) #1039 [Caleb Tennis]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1104 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 4 | ||||
-rwxr-xr-x | activerecord/test/fixtures/company.rb | 3 |
2 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index cd9fa7cb18..71e2ab01f8 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -250,6 +250,10 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal 1, Firm.find_first.clients_using_counter_sql.size assert_equal 0, Firm.find_first.clients_using_zero_counter_sql.size end + + def test_counting_non_existant_items_using_sql + assert_equal 0, Firm.find_first.no_clients_using_counter_sql.size + end def test_belongs_to_sanity c = Client.new diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 17a71e7e20..d4bdd7982e 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -17,6 +17,9 @@ class Firm < Company has_many :clients_using_zero_counter_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}', :counter_sql => 'SELECT 0 FROM companies WHERE client_of = #{id}' + 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_one :account, :dependent => true end |