diff --git a/lib/bulletmark_repairer/controller_corrector.rb b/lib/bulletmark_repairer/controller_corrector.rb index 1bba8d8..91c39e4 100644 --- a/lib/bulletmark_repairer/controller_corrector.rb +++ b/lib/bulletmark_repairer/controller_corrector.rb @@ -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 diff --git a/lib/bulletmark_repairer/corrector.rb b/lib/bulletmark_repairer/corrector.rb index 8c2db74..5da8f17 100644 --- a/lib/bulletmark_repairer/corrector.rb +++ b/lib/bulletmark_repairer/corrector.rb @@ -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 @@ -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