aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Polushkin <dmitry.polushkin@gmail.com>2013-06-28 12:07:34 +0100
committerDmitry Polushkin <dmitry.polushkin@gmail.com>2013-06-28 13:51:00 +0100
commit1cf6871a9e3124ff6b74a315c4bef9dc427da5f9 (patch)
tree1ea82db280fee3991e05877e0fc6b2ba61608fd4
parent7c69a829a311a31109939cff19b700b36b97d5c4 (diff)
downloadrails-1cf6871a9e3124ff6b74a315c4bef9dc427da5f9.tar.gz
rails-1cf6871a9e3124ff6b74a315c4bef9dc427da5f9.tar.bz2
rails-1cf6871a9e3124ff6b74a315c4bef9dc427da5f9.zip
find_in_batches should work without logger
-rw-r--r--activerecord/lib/active_record/relation/batches.rb4
-rw-r--r--activerecord/test/cases/batches_test.rb10
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 41291844fc..341769b5c4 100644
--- a/activerecord/lib/active_record/relation/batches.rb
+++ b/activerecord/lib/active_record/relation/batches.rb
@@ -78,8 +78,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 e09fa95756..90c5e91b4a 100644
--- a/activerecord/test/cases/batches_test.rb
+++ b/activerecord/test/cases/batches_test.rb
@@ -50,6 +50,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|