diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2014-01-29 15:02:13 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2014-01-29 23:52:41 -0500 |
commit | 642106e277334e75ff1ae8d8a03f5fef37cf0671 (patch) | |
tree | f269f2cfc5abf05dd7723e388201ee6a06d67d11 | |
parent | fec1028d088294c30f568e46db3bbd054a9330ff (diff) | |
download | rails-642106e277334e75ff1ae8d8a03f5fef37cf0671.tar.gz rails-642106e277334e75ff1ae8d8a03f5fef37cf0671.tar.bz2 rails-642106e277334e75ff1ae8d8a03f5fef37cf0671.zip |
find_in_batches should not mutate its argument
-rw-r--r-- | activerecord/lib/active_record/relation/batches.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/batches_test.rb | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index dfcfef2ad2..666cef80a9 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -104,8 +104,8 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb index 1161b57514..8216d74cb3 100644 --- a/activerecord/test/cases/batches_test.rb +++ b/activerecord/test/cases/batches_test.rb @@ -153,6 +153,12 @@ class EachTest < ActiveRecord::TestCase 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 |