From 0914072ee57034462e6e67cc0dc2a203f119d2fe Mon Sep 17 00:00:00 2001 From: Aidan Coyle Date: Sun, 23 Oct 2022 15:18:46 -0500 Subject: [PATCH] Fix ConditionNotSupportedError raise This constant does not exist in this scope. Running the test in the PR without the associated code change results in: "uninitialized constant JobIteration::ActiveRecordBatchEnumerator::ConditionNotSupportedError" --- lib/job-iteration/active_record_batch_enumerator.rb | 2 +- test/unit/active_record_batch_enumerator_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/job-iteration/active_record_batch_enumerator.rb b/lib/job-iteration/active_record_batch_enumerator.rb index b48c7617..3972693f 100644 --- a/lib/job-iteration/active_record_batch_enumerator.rb +++ b/lib/job-iteration/active_record_batch_enumerator.rb @@ -26,7 +26,7 @@ def initialize(relation, columns: nil, batch_size: 100, cursor: nil) end if relation.arel.orders.present? || relation.arel.taken.present? - raise ConditionNotSupportedError + raise JobIteration::ActiveRecordCursor::ConditionNotSupportedError end @base_relation = relation.reorder(@columns.join(",")) diff --git a/test/unit/active_record_batch_enumerator_test.rb b/test/unit/active_record_batch_enumerator_test.rb index ba1dcfb8..79da7793 100644 --- a/test/unit/active_record_batch_enumerator_test.rb +++ b/test/unit/active_record_batch_enumerator_test.rb @@ -125,6 +125,12 @@ class ActiveRecordBatchEnumeratorTest < IterationUnitTest assert_equal expected_num_queries, queries.size end + test "enumerator will raise ConditionNotSupportedError if the relation is ordered" do + assert_raise(JobIteration::ActiveRecordCursor::ConditionNotSupportedError) do + build_enumerator(relation: Product.order(created_at: :desc)) + end + end + private def build_enumerator(relation: Product.all, batch_size: 2, columns: nil, cursor: nil)