diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-06-28 06:00:20 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-06-28 06:00:20 -0700 |
commit | 8f63515f6efbc5c342dc9af9aa936e72261a18fe (patch) | |
tree | 2a06d57aec360e76150c8e658ec58bd1fa512137 | |
parent | 5e6de3942ffbc667d1f43860a0c80dd8031a0c60 (diff) | |
parent | 1cf6871a9e3124ff6b74a315c4bef9dc427da5f9 (diff) | |
download | rails-8f63515f6efbc5c342dc9af9aa936e72261a18fe.tar.gz rails-8f63515f6efbc5c342dc9af9aa936e72261a18fe.tar.bz2 rails-8f63515f6efbc5c342dc9af9aa936e72261a18fe.zip |
Merge pull request #11161 from dmitry/find_in_batches_works_without_logger
ActiveRecord find_in_batches should work without logger
When I set logger to nil both methods from Batches module find_in_batches or find_each should work anyway.
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/batches_test.rb | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index 91ea1756c4..fd8496442e 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -89,8 +89,8 @@ module ActiveRecord relation = self - unless arel.orders.blank? && arel.taken.blank? - ActiveRecord::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size") + if logger && (arel.orders.present? || arel.taken.present?) + logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size") end start = options.delete(:start) diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 1d6676da1c..38c2560d69 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -68,6 +68,16 @@ class EachTest < ActiveRecord::TestCase Post.order("title").find_each { |post| post } end + def test_logger_not_required + previous_logger = ActiveRecord::Base.logger + ActiveRecord::Base.logger = nil + assert_nothing_raised do + Post.limit(1).find_each { |post| post } + end + ensure + ActiveRecord::Base.logger = previous_logger + end + def test_find_in_batches_should_return_batches assert_queries(@total + 1) do Post.find_in_batches(:batch_size => 1) do |batch| |