4 class EachTest
< ActiveRecord
::TestCase
8 @posts = Post
.all(:order => "id asc")
12 def test_each_should_excecute_one_query_per_batch
13 assert_queries(Post
.count
+ 1) do
14 Post
.find_each(:batch_size => 1) do |post
|
15 assert_kind_of Post
, post
20 def test_each_should_raise_if_the_order_is_set
21 assert_raise(RuntimeError
) do
22 Post
.find_each(:order => "title") { |post
| post
}
26 def test_each_should_raise_if_the_limit_is_set
27 assert_raise(RuntimeError
) do
28 Post
.find_each(:limit => 1) { |post
| post
}
32 def test_find_in_batches_should_return_batches
33 assert_queries(Post
.count
+ 1) do
34 Post
.find_in_batches(:batch_size => 1) do |batch
|
35 assert_kind_of Array
, batch
36 assert_kind_of Post
, batch
.first
41 def test_find_in_batches_should_start_from_the_start_option
42 assert_queries(Post
.count
) do
43 Post
.find_in_batches(:batch_size => 1, :start => 2) do |batch
|
44 assert_kind_of Array
, batch
45 assert_kind_of Post
, batch
.first
50 def test_find_in_batches_shouldnt_excute_query_unless_needed
51 post_count
= Post
.count
54 Post
.find_in_batches(:batch_size => post_count
) {|batch
| assert_kind_of Array
, batch
}
58 Post
.find_in_batches(:batch_size => post_count
+ 1) {|batch
| assert_kind_of Array
, batch
}