aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-06-25 20:09:17 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-06-25 20:09:17 -0300
commit840c552047a660d0a66883fb9c0cb144d5e728fb (patch)
tree1d7951a9163a3c7b9c80be2ef4a4eb3e53ec013a /activerecord/test/cases
parent755069ee4e954ae66f6a8bb4a810c2dbb1bbc0d7 (diff)
parent25042359b388a73bae798e023276df59e53c74e2 (diff)
downloadrails-840c552047a660d0a66883fb9c0cb144d5e728fb.tar.gz
rails-840c552047a660d0a66883fb9c0cb144d5e728fb.tar.bz2
rails-840c552047a660d0a66883fb9c0cb144d5e728fb.zip
Merge pull request #10992 from Empact/find-each-enumerator
When .find_each is called without a block, return an Enumerator.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/batches_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb
index e09fa95756..1d6676da1c 100644
--- a/activerecord/test/cases/batches_test.rb
+++ b/activerecord/test/cases/batches_test.rb
@@ -26,6 +26,24 @@ class EachTest < ActiveRecord::TestCase
end
end
+ def test_each_should_return_an_enumerator_if_no_block_is_present
+ assert_queries(1) do
+ Post.find_each(:batch_size => 100000).with_index do |post, index|
+ assert_kind_of Post, post
+ assert_kind_of Integer, index
+ end
+ 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|
+ assert_kind_of Post, post
+ assert_kind_of Integer, index
+ end
+ end
+ end
+
def test_each_should_raise_if_select_is_set_without_id
assert_raise(RuntimeError) do
Post.select(:title).find_each(:batch_size => 1) { |post| post }