Class: RuboCop::Cop::Mable::NoWardenInGraphQL

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/mable/no_warden_in_graph_ql.rb

Overview

This cop checks for the usage of Warden::Test::Helpers and related methods within GraphQL specs. It disallows the use of Warden.test_mode!, login_as, and user.reload.

Examples:

# bad
Warden.test_mode!
(user)
user.reload
include Warden::Test::Helpers

# good
# Use graphql helper method

Constant Summary collapse

MSG =
'Do not use `%<method>s` in GraphQL specs. Use graphql helper method instead.'
RESTRICT_ON_SEND =
%i[test_mode! login_as reload].freeze
RESTRICT_ON_INCLUDE =
%i[Warden::Test::Helpers].freeze

Instance Method Summary collapse

Instance Method Details

#on_const(node) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/rubocop/cop/mable/no_warden_in_graph_ql.rb', line 53

def on_const(node)
  return unless in_graphql?(node) && bad_include?(node)

  add_offense(node, message: format(MSG, method: 'include Warden::Test::Helpers')) do |corrector|
    correct_offense(corrector, node)
  end
end

#on_send(node) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/rubocop/cop/mable/no_warden_in_graph_ql.rb', line 44

def on_send(node)
  return unless in_graphql?(node) && bad_method?(node)

  method_name = node.method_name
  add_offense(node, message: format(MSG, method: method_name)) do |corrector|
    correct_offense(corrector, node)
  end
end