class RubbyCop::Cop::Rails::SkipsModelValidations
This cop checks for the use of methods which skip validations which are listed in guides.rubyonrails.org/active_record_validations.html#skipping-validations
@example
# bad Article.first.decrement!(:view_count) DiscussionBoard.decrement_counter(:post_count, 5) Article.first.increment!(:view_count) DiscussionBoard.increment_counter(:post_count, 5) person.toggle :active product.touch Billing.update_all("category = 'authorized', author = 'David'") user.update_attribute(website: 'example.com') user.update_columns(last_request_at: Time.current) Post.update_counters 5, comment_count: -1, action_count: 1 # good user.update_attributes(website: 'example.com')
Constants
- METHODS_WITH_ARGUMENTS
- MSG
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubbycop/cop/rails/skips_model_validations.rb, line 39 def on_send(node) return unless blacklist.include?(node.method_name.to_s) _receiver, method_name, *args = *node if METHODS_WITH_ARGUMENTS.include?(method_name.to_s) && args.empty? return end add_offense(node, :selector) end
Private Instance Methods
blacklist()
click to toggle source
# File lib/rubbycop/cop/rails/skips_model_validations.rb, line 57 def blacklist cop_config['Blacklist'] || [] end
message(node)
click to toggle source
# File lib/rubbycop/cop/rails/skips_model_validations.rb, line 53 def message(node) format(MSG, node.method_name) end