Skip to content

Commit

Permalink
Merge pull request #266 from ifad/bugfix/177-fix-batches
Browse files Browse the repository at this point in the history
Fix `find_each` and in batches
  • Loading branch information
tagliala authored Feb 3, 2024
2 parents 02af493 + 3bf9659 commit 5f05360
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/chrono_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.history_models

ActiveRecord::Associations::Preloader::ThroughAssociation.prepend ChronoModel::Patches::Preloader::ThroughAssociation

ActiveRecord::Batches::BatchEnumerator.prepend ChronoModel::Patches::Batches::BatchEnumerator
ActiveRecord::Batches.prepend ChronoModel::Patches::Batches
end

ActiveSupport.on_load :after_initialize do
Expand Down
12 changes: 4 additions & 8 deletions lib/chrono_model/patches/batches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
module ChronoModel
module Patches
module Batches
module BatchEnumerator
def each(&block)
if @relation.try(:history?)
@relation.with_hid_pkey { super }
else
super
end
end
def in_batches(**)
return super unless try(:history?)

with_hid_pkey { super }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chrono_model/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ChronoModel
VERSION = '3.0.0'
VERSION = '3.0.1'
end
4 changes: 4 additions & 0 deletions spec/chrono_model/time_machine/batches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
RSpec.describe ChronoModel::TimeMachine do
include ChronoTest::TimeMachine::Helpers

describe '.find_each' do
it { expect(Foo.history.find_each(batch_size: 2).count).to eq Foo.history.count }
end

describe '.in_batches' do
let(:foo_in_batches_of_two) do
[
Expand Down

0 comments on commit 5f05360

Please sign in to comment.