diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2014-01-29 15:42:07 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2014-02-05 16:53:02 -0500 |
commit | 13d2696c10726afecd393753fcac88c5a9907d8c (patch) | |
tree | 9a505cd8dc1a66b1afbf04e324fb6597c7563f20 /activerecord/test | |
parent | d37f395be86d131d0218dadd189771f99b06874f (diff) | |
download | rails-13d2696c10726afecd393753fcac88c5a9907d8c.tar.gz rails-13d2696c10726afecd393753fcac88c5a9907d8c.tar.bz2 rails-13d2696c10726afecd393753fcac88c5a9907d8c.zip |
Return sized enumerator from Batches#find_each
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/batches_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/result_test.rb | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 4ee09a640e..c12fa03015 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -35,6 +35,14 @@ class EachTest < ActiveRecord::TestCase end end + if Enumerator.method_defined? :size + def test_each_should_return_a_sized_enumerator + assert_equal 11, Post.find_each(:batch_size => 1).size + assert_equal 5, Post.find_each(:batch_size => 2, :start => 7).size + assert_equal 11, Post.find_each(:batch_size => 10_000).size + end + end + def test_each_enumerator_should_execute_one_query_per_batch assert_queries(@total + 1) do Post.find_each(:batch_size => 1).with_index do |post, index| diff --git a/activerecord/test/cases/result_test.rb b/activerecord/test/cases/result_test.rb index edaeb85211..2131b32a0c 100644 --- a/activerecord/test/cases/result_test.rb +++ b/activerecord/test/cases/result_test.rb @@ -30,5 +30,11 @@ module ActiveRecord assert_kind_of Integer, index end end + + if Enumerator.method_defined? :size + def test_each_without_block_returns_a_sized_enumerator + assert_equal 3, result.each.size + end + end end end |