Skip to content

Commit

Permalink
Merge pull request #6 from ydah/fix-redundant-autocorrect
Browse files Browse the repository at this point in the history
Fix a redundant auto-correct for multiple tests with n+1 queries when running RSpec
  • Loading branch information
makicamel authored Oct 17, 2023
2 parents 4bdd001 + 9cfe2b8 commit 5bf3720
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions lib/bulletmark_repairer/controller_corrector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ def insert_includes(node:)
return unless node.respond_to?(:to_sexp_array)

type, identifier = node.to_sexp_array.take(2)

if type == :ivasgn && identifier == instance_variable_name
insert_after node.children.last.location.expression, ".includes(#{associations})"
@patched = true
inserted = ".includes(#{associations})"
unless node.location.expression.source.include?(inserted)
insert_after node.children.last.location.expression, inserted
@patched = true
end
else
node
.children
Expand Down
14 changes: 10 additions & 4 deletions lib/bulletmark_repairer/corrector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def insert_includes(node:)

# TODO: Patch Enumerable methods other than each and map
if node.children.last.in?(%i[each map])
insert_after node.children[0].location.expression, ".includes(#{associations})"
@patched = true
inserted = ".includes(#{associations})"
unless node.location.expression.source.include?(inserted)
insert_after node.children[0].location.expression, ".includes(#{associations})"
@patched = true
end
else
node.children.each { |child_node| insert_includes(node: child_node) }
end
Expand All @@ -39,8 +42,11 @@ def insert_includes_for_vasgn(node:, type:)
return unless node.location.expression.line <= line_no && line_no <= node.location.expression.last_line

if node.type == type
insert_after node.children.last.location.expression, ".includes(#{associations})"
@patched = true
inserted = ".includes(#{associations})"
unless node.location.expression.source.include?(inserted)
insert_after node.children.last.location.expression, ".includes(#{associations})"
@patched = true
end
else
node.children.each { |child_node| insert_includes_for_vasgn(node: child_node, type: type) }
end
Expand Down

0 comments on commit 5bf3720

Please sign in to comment.