diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-30 04:10:48 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-30 04:10:48 -0800 |
commit | 7f5466d58299db35a3d320e0b526001ae3be11a7 (patch) | |
tree | 93216f765177f068ed882994582af596a50980d7 /activerecord | |
parent | 02f9f3314244513fce0a94acef08318d67d6707f (diff) | |
parent | 642106e277334e75ff1ae8d8a03f5fef37cf0671 (diff) | |
download | rails-7f5466d58299db35a3d320e0b526001ae3be11a7.tar.gz rails-7f5466d58299db35a3d320e0b526001ae3be11a7.tar.bz2 rails-7f5466d58299db35a3d320e0b526001ae3be11a7.zip |
Merge pull request #13878 from marcandre/leave_my_options_alone
find_in_batches should not mutate its argument
Diffstat (limited to 'activerecord')
-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 |