class RuboCop::Cop::Rails::SkipsModelValidations


user.touch
# good
person.toggle :active
DiscussionBoard.increment_counter(:post_count, 5)
DiscussionBoard.decrement_counter(:post_count, 5)
# bad
@example AllowedMethods: [“touch”]
FileUtils.touch(‘file’)
user.update(website: ‘example.com’)
# good
Post.update_counters 5, comment_count: -1, action_count: 1
user.update_columns(last_request_at: Time.current)
user.update_attribute(:website, ‘example.com’)
Billing.update_all(“category = ‘authorized’, author = ‘David’”)
product.touch
person.toggle :active
DiscussionBoard.increment_counter(:post_count, 5)
Article.first.increment!(:view_count)
DiscussionBoard.decrement_counter(:post_count, 5)
Article.first.decrement!(:view_count)
# bad
@example
Methods may be ignored from this rule by configuring a ‘AllowedMethods`.
validations which are listed in
Checks for the use of methods which skip

def allowed_method?(node)

def allowed_method?(node)
  METHODS_WITH_ARGUMENTS.include?(node.method_name.to_s) &&
    !node.arguments?
end

def allowed_methods

def allowed_methods
  obsolete_result = cop_config['Whitelist']
  if obsolete_result
    warn '`Whitelist` has been renamed to `AllowedMethods`.' unless @displayed_allowed_warning
    @displayed_allowed_warning = true
    return obsolete_result
  end
  cop_config['AllowedMethods'] || []
end

def forbidden_methods

def forbidden_methods
  obsolete_result = cop_config['Blacklist']
  if obsolete_result
    warn '`Blacklist` has been renamed to `ForbiddenMethods`.' unless @displayed_forbidden_warning
    @displayed_forbidden_warning = true
    return obsolete_result
  end
  cop_config['ForbiddenMethods'] || []
end

def initialize(*)

def initialize(*)
  super
  @displayed_allowed_warning = false
  @displayed_forbidden_warning = false
end

def message(node)

def message(node)
  format(MSG, method: node.method_name)
end

def on_send(node)

def on_send(node)
  return if allowed_methods.include?(node.method_name.to_s)
  return unless forbidden_methods.include?(node.method_name.to_s)
  return if allowed_method?(node)
  return if good_touch?(node)
  return if good_insert?(node)
  add_offense(node.loc.selector, message: message(node))
end