Skip to content

Commit

Permalink
Merge pull request #289 from packrat386/fix_condition_not_supported_r…
Browse files Browse the repository at this point in the history
…aise

Fix ConditionNotSupportedError raise
  • Loading branch information
Mangara authored Oct 26, 2022
2 parents 57b9c0e + 0914072 commit 5e0147f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/job-iteration/active_record_batch_enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(","))
Expand Down
6 changes: 6 additions & 0 deletions test/unit/active_record_batch_enumerator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5e0147f

Please sign in to comment.