diff --git a/lib/rubocop/cop/migration/batch_in_batches.rb b/lib/rubocop/cop/migration/batch_in_batches.rb index 42fc001..5ab55e5 100644 --- a/lib/rubocop/cop/migration/batch_in_batches.rb +++ b/lib/rubocop/cop/migration/batch_in_batches.rb @@ -71,17 +71,7 @@ def autocorrect( corrector, node ) - range = node.location.selector.with( - end_pos: node.source_range.end_pos - ) - corrector.replace( - range, - <<~TEXT.chomp - in_batches do |relation| - relation.#{range.source} - end - TEXT - ) + corrector.insert_before(node.location.selector, 'in_batches.') end # @param node [RuboCop::AST::SendNode] diff --git a/spec/rubocop/cop/migration/batch_in_batches_spec.rb b/spec/rubocop/cop/migration/batch_in_batches_spec.rb index 916ac0f..5286baf 100644 --- a/spec/rubocop/cop/migration/batch_in_batches_spec.rb +++ b/spec/rubocop/cop/migration/batch_in_batches_spec.rb @@ -41,9 +41,7 @@ def change expect_correction(<<~RUBY) class BackfillUsersSomeColumn < ActiveRecord::Migration[7.0] def change - User.in_batches do |relation| - relation.update_all(some_column: 'some value') - end + User.in_batches.update_all(some_column: 'some value') end end RUBY @@ -64,9 +62,7 @@ def change expect_correction(<<~RUBY) class BackfillUsersSomeColumn < ActiveRecord::Migration[7.0] def change - User.in_batches do |relation| - relation.delete_all - end + User.in_batches.delete_all end end RUBY