Permalink
Browse files

Merge pull request #13878 from marcandre/leave_my_options_alone

find_in_batches should not mutate its argument
  • Loading branch information...
2 parents 02f9f33 + 642106e commit 7f5466d58299db35a3d320e0b526001ae3be11a7 @rafaelfranca rafaelfranca committed Jan 30, 2014
Showing with 8 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/relation/batches.rb
  2. +6 −0 activerecord/test/cases/batches_test.rb
@@ -104,8 +104,8 @@ def find_in_batches(options = {})
logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
end
- start = options.delete(:start)
- batch_size = options.delete(:batch_size) || 1000
+ start = options[:start]
+ batch_size = options[:batch_size] || 1000
relation = relation.reorder(batch_order).limit(batch_size)
records = start ? relation.where(table[primary_key].gteq(start)).to_a : relation.to_a
@@ -153,6 +153,12 @@ def test_find_in_batches_should_not_ignore_the_default_scope_if_it_is_other_then
assert_equal special_posts_ids, posts.map(&:id)
end
+ def test_find_in_batches_should_not_modify_passed_options
+ assert_nothing_raised do
+ Post.find_in_batches({ batch_size: 42, start: 1 }.freeze){}
+ end
+ end
+
def test_find_in_batches_should_use_any_column_as_primary_key
nick_order_subscribers = Subscriber.order('nick asc')
start_nick = nick_order_subscribers.second.nick

0 comments on commit 7f5466d

Please sign in to comment.