aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/batches_test.rb
diff options
context:
space:
mode:
authorScott Ringwelski <sgringwe@mtu.edu>2016-02-01 20:17:17 -0800
committerScott Ringwelski <sgringwe@mtu.edu>2016-02-02 15:05:16 -0800
commit08a748118377f22823e06315f57db16e1ce3a7c3 (patch)
tree3d8142294799177b9b7a0be86d1fda7ca9eb960b /activerecord/test/cases/batches_test.rb
parent49e0c4e8642a0160bd01c4490b4babe89108da48 (diff)
downloadrails-08a748118377f22823e06315f57db16e1ce3a7c3.tar.gz
rails-08a748118377f22823e06315f57db16e1ce3a7c3.tar.bz2
rails-08a748118377f22823e06315f57db16e1ce3a7c3.zip
Add initial support for allowing an error on order or limit of queries being ignored in batches
add some documentation and add 4 tests regarding error vs. warning behavior fix a typo when referring to the message go back to default in tests so that ordering is not important. use a constant instead of method. fix assert_nothing_raised call. use self.klass to allow per class configuration remove logger warn assets as that is tested elsewhere. pass error_on_ignore through find_each and find_in_batches also. add blocks to the finds so that the code is actually executed put the setting back to default in an ensure Add a changelog entry
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 3602ee7ba2..f44c82cc58 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 = []