aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/batches_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-03-01 14:36:32 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-03-01 14:36:32 -0300
commitbc57930e09d20ee2cdc4b5aa7200b155ba755f22 (patch)
tree4df498de85a52d4bc07279362d586d23862d29f4 /activerecord/test/cases/batches_test.rb
parentf2c707a64ee8683ee7bc4f1bc0254afcaa0ff676 (diff)
parent08a748118377f22823e06315f57db16e1ce3a7c3 (diff)
downloadrails-bc57930e09d20ee2cdc4b5aa7200b155ba755f22.tar.gz
rails-bc57930e09d20ee2cdc4b5aa7200b155ba755f22.tar.bz2
rails-bc57930e09d20ee2cdc4b5aa7200b155ba755f22.zip
Merge pull request #23417 from sgringwe/master
Add option to error on ignored order or limit
Diffstat (limited to 'activerecord/test/cases/batches_test.rb')
-rw-r--r--activerecord/test/cases/batches_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/test/cases/batches_test.rb b/activerecord/test/cases/batches_test.rb
index 84aac3e721..91ff5146fd 100644
--- a/activerecord/test/cases/batches_test.rb
+++ b/activerecord/test/cases/batches_test.rb
@@ -164,6 +164,42 @@ class EachTest < ActiveRecord::TestCase
assert_equal posts(:welcome).id, posts.first.id
end
+ def test_find_in_batches_should_error_on_ignore_the_order
+ assert_raise(ArgumentError) do
+ PostWithDefaultScope.find_in_batches(error_on_ignore: true){}
+ end
+ end
+
+ def test_find_in_batches_should_not_error_if_config_overriden
+ # Set the config option which will be overriden
+ prev = ActiveRecord::Base.error_on_ignored_order_or_limit
+ ActiveRecord::Base.error_on_ignored_order_or_limit = true
+ assert_nothing_raised do
+ PostWithDefaultScope.find_in_batches(error_on_ignore: false){}
+ end
+ ensure
+ # Set back to default
+ ActiveRecord::Base.error_on_ignored_order_or_limit = prev
+ end
+
+ def test_find_in_batches_should_error_on_config_specified_to_error
+ # Set the config option
+ prev = ActiveRecord::Base.error_on_ignored_order_or_limit
+ ActiveRecord::Base.error_on_ignored_order_or_limit = true
+ assert_raise(ArgumentError) do
+ PostWithDefaultScope.find_in_batches(){}
+ end
+ ensure
+ # Set back to default
+ ActiveRecord::Base.error_on_ignored_order_or_limit = prev
+ end
+
+ def test_find_in_batches_should_not_error_by_default
+ assert_nothing_raised do
+ PostWithDefaultScope.find_in_batches(){}
+ end
+ end
+
def test_find_in_batches_should_not_ignore_the_default_scope_if_it_is_other_then_order
special_posts_ids = SpecialPostWithDefaultScope.all.map(&:id).sort
posts = []