Permalink
Browse files

Merge pull request #11161 from dmitry/find_in_batches_works_without_l…

…ogger

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.
  • Loading branch information...
1 parent 35a289a commit 6e80d12612d68a8cbbea60ba59001508654aa628 @carlosantoniodasilva carlosantoniodasilva committed Jun 28, 2013
Showing with 12 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/relation/batches.rb
  2. +10 −0 activerecord/test/cases/batches_test.rb
@@ -58,8 +58,8 @@ def find_in_batches(options = {})
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)
@@ -50,6 +50,16 @@ def test_warn_if_order_scope_is_set
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(Post.count + 1) do
Post.find_in_batches(:batch_size => 1) do |batch|

0 comments on commit 6e80d12

Please sign in to comment.