Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #10702 from divineforest/use-total-in-batches-test

Use @total variable created in the setup of batches tests instead of counting again.
  • Loading branch information...
commit 36e7be2214ec9bcc8ca0f3545ad1d3b687259806 2 parents bff89a2 + 4a4a566
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 5 additions and 7 deletions.
  1. +5 −7 activerecord/test/cases/batches_test.rb
View
12 activerecord/test/cases/batches_test.rb
@@ -12,7 +12,7 @@ def setup
end
def test_each_should_execute_one_query_per_batch
- assert_queries(Post.count + 1) do
+ assert_queries(@total + 1) do
Post.find_each(:batch_size => 1) do |post|
assert_kind_of Post, post
end
@@ -51,7 +51,7 @@ def test_warn_if_order_scope_is_set
end
def test_find_in_batches_should_return_batches
- assert_queries(Post.count + 1) do
+ assert_queries(@total + 1) do
Post.find_in_batches(:batch_size => 1) do |batch|
assert_kind_of Array, batch
assert_kind_of Post, batch.first
@@ -60,7 +60,7 @@ def test_find_in_batches_should_return_batches
end
def test_find_in_batches_should_start_from_the_start_option
- assert_queries(Post.count) do
+ assert_queries(@total) do
Post.find_in_batches(:batch_size => 1, :start => 2) do |batch|
assert_kind_of Array, batch
assert_kind_of Post, batch.first
@@ -69,14 +69,12 @@ def test_find_in_batches_should_start_from_the_start_option
end
def test_find_in_batches_shouldnt_execute_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 }
+ Post.find_in_batches(:batch_size => @total) {|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 }
+ Post.find_in_batches(:batch_size => @total + 1) {|batch| assert_kind_of Array, batch }
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.