Skip to content

Commit

Permalink
Merge pull request #17 from r7kamura/in-batches-inline-autocorrect
Browse files Browse the repository at this point in the history
Prefer inline `in_batches` on `Migration/BatchInBatches` autocorrection
  • Loading branch information
r7kamura committed Jan 27, 2024
2 parents 8ade242 + 6b28d0d commit b4c0686
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
12 changes: 1 addition & 11 deletions lib/rubocop/cop/migration/batch_in_batches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 2 additions & 6 deletions spec/rubocop/cop/migration/batch_in_batches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b4c0686

Please sign in to comment.