diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 315f7c2..e23a03b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp` -# using RuboCop version 1.59.0. +# using RuboCop version 1.60.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new diff --git a/lib/chrono_model.rb b/lib/chrono_model.rb index a7ce306..d4a87fd 100644 --- a/lib/chrono_model.rb +++ b/lib/chrono_model.rb @@ -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 diff --git a/lib/chrono_model/patches/batches.rb b/lib/chrono_model/patches/batches.rb index 5d7e52c..debacbe 100644 --- a/lib/chrono_model/patches/batches.rb +++ b/lib/chrono_model/patches/batches.rb @@ -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 diff --git a/lib/chrono_model/version.rb b/lib/chrono_model/version.rb index 55ac1f4..33d68ad 100644 --- a/lib/chrono_model/version.rb +++ b/lib/chrono_model/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ChronoModel - VERSION = '3.0.0' + VERSION = '3.0.1' end diff --git a/spec/chrono_model/time_machine/batches_spec.rb b/spec/chrono_model/time_machine/batches_spec.rb index b44ceb4..050e2ea 100644 --- a/spec/chrono_model/time_machine/batches_spec.rb +++ b/spec/chrono_model/time_machine/batches_spec.rb @@ -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 [