diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-05-21 05:51:11 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-05-21 05:51:11 -0700 |
commit | 36e7be2214ec9bcc8ca0f3545ad1d3b687259806 (patch) | |
tree | 345037ac9571c03bc0ee8999074bdbc6d7e6fa96 | |
parent | bff89a2022aedec60929f6d6744eefc84a5c102a (diff) | |
parent | 4a4a566b122e8bf080d0b9c5964ae46d523c9dc6 (diff) | |
download | rails-36e7be2214ec9bcc8ca0f3545ad1d3b687259806.tar.gz rails-36e7be2214ec9bcc8ca0f3545ad1d3b687259806.tar.bz2 rails-36e7be2214ec9bcc8ca0f3545ad1d3b687259806.zip |
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.
-rw-r--r-- | activerecord/test/cases/batches_test.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index ba6b0b1362..e09fa95756 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -12,7 +12,7 @@ class EachTest < ActiveRecord::TestCase 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 @@ class EachTest < ActiveRecord::TestCase 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 @@ class EachTest < ActiveRecord::TestCase 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 @@ class EachTest < ActiveRecord::TestCase 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 |