aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/batches_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/batches_test.rb')
-rw-r--r--activerecord/test/cases/batches_test.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb
index 108d679108..5009a90846 100644
--- a/activerecord/test/cases/batches_test.rb
+++ b/activerecord/test/cases/batches_test.rb
@@ -11,7 +11,7 @@ class EachTest < ActiveRecord::TestCase
def test_each_should_excecute_one_query_per_batch
assert_queries(Post.count + 1) do
- Post.each(:batch_size => 1) do |post|
+ Post.find_each(:batch_size => 1) do |post|
assert_kind_of Post, post
end
end
@@ -19,13 +19,13 @@ class EachTest < ActiveRecord::TestCase
def test_each_should_raise_if_the_order_is_set
assert_raise(RuntimeError) do
- Post.each(:order => "title") { |post| post }
+ Post.find_each(:order => "title") { |post| post }
end
end
def test_each_should_raise_if_the_limit_is_set
assert_raise(RuntimeError) do
- Post.each(:limit => 1) { |post| post }
+ Post.find_each(:limit => 1) { |post| post }
end
end
@@ -46,4 +46,16 @@ class EachTest < ActiveRecord::TestCase
end
end
end
+
+ def test_find_in_batches_shouldnt_excute_query_unless_needed
+ post_count = Post.count
+
+ assert_queries(2) do
+ Post.find_in_batches(:batch_size => post_count) {|batch| assert_kind_of Array, batch }
+ end
+
+ assert_queries(1) do
+ Post.find_in_batches(:batch_size => post_count + 1) {|batch| assert_kind_of Array, batch }
+ end
+ end
end \ No newline at end of file