Class: RuboCop::Cop::Netlify::RequestTestsParamEncoding

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/netlify/request_tests_param_encoding.rb

Overview

This cop enforces the test to use ‘as:` option for encoding the request with a content type.

Examples:

# bad
post "api/v1/user", params: { name: "Esteban" }

# good
post "api/v1/user", params: { name: "Esteban" }, as: :json

Constant Summary collapse

MSG =
"%<http_method>s with params should be used with as: to specify a param encoding"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/rubocop/cop/netlify/request_tests_param_encoding.rb', line 30

def on_send(node)
  request_method(node) do |http_method, option_pairs|
    params = option_pairs.detect { |pair| has_params?(pair) }
    as = option_pairs.detect { |pair| has_as?(pair) }
    if params && !as
      message = format(MSG, http_method: http_method)
      add_offense(node, message: message)
    end
  end
end