diff options
Diffstat (limited to 'rubocop/cop/database/establish_connection.rb')
-rw-r--r-- | rubocop/cop/database/establish_connection.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/rubocop/cop/database/establish_connection.rb b/rubocop/cop/database/establish_connection.rb new file mode 100644 index 00000000000..20454887ce2 --- /dev/null +++ b/rubocop/cop/database/establish_connection.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Database + class EstablishConnection < RuboCop::Cop::Cop + MSG = "Don't establish new database connections, as this slows down " \ + 'tests and may result in new connections using an incorrect configuration' + + def_node_matcher :establish_connection?, <<~PATTERN + (send (const ...) :establish_connection ...) + PATTERN + + def on_send(node) + add_offense(node, location: :expression) if establish_connection?(node) + end + end + end + end +end |