diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-03-11 14:52:51 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-11 15:07:24 +0000 |
commit | f23adf0ed4bd596c9e7688455489a79f8b35eb3f (patch) | |
tree | 2afc6fd0a1277a036e19b207a7299572aebdfd77 /activerecord/test | |
parent | 0b6f514947c38bf7af2b7e98905a49a94832e5f6 (diff) | |
download | rails-f23adf0ed4bd596c9e7688455489a79f8b35eb3f.tar.gz rails-f23adf0ed4bd596c9e7688455489a79f8b35eb3f.tar.bz2 rails-f23adf0ed4bd596c9e7688455489a79f8b35eb3f.zip |
Add tests for AssociationCollection#find_each and AssociationCollection#find_in_batches
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index b7fa9d9d7c..99e4dc7e6e 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -219,6 +219,45 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 1, firm.clients.find(:all, :conditions => "name = 'Summit'").length end + def test_find_each + firm = companies(:first_firm) + + assert ! firm.clients.loaded? + + assert_queries(3) do + firm.clients.find_each(:batch_size => 1) {|c| assert_equal firm.id, c.firm_id } + end + + assert ! firm.clients.loaded? + end + + def test_find_each_with_conditions + firm = companies(:first_firm) + + assert_queries(2) do + firm.clients.find_each(:batch_size => 1, :conditions => {:name => "Microsoft"}) do |c| + assert_equal firm.id, c.firm_id + assert_equal "Microsoft", c.name + end + end + + assert ! firm.clients.loaded? + end + + def test_find_in_batches + firm = companies(:first_firm) + + assert ! firm.clients.loaded? + + assert_queries(2) do + firm.clients.find_in_batches(:batch_size => 2) do |clients| + clients.each {|c| assert_equal firm.id, c.firm_id } + end + end + + assert ! firm.clients.loaded? + end + def test_find_all_sanitized firm = Firm.find(:first) summit = firm.clients.find(:all, :conditions => "name = 'Summit'") |