Sha256: 7043915c64c6b538d89e0ab961fd11fd5c5d0146260acc9960b1637293fd257e

Contents?: true

Size: 993 Bytes

Versions: 4

Compression:

Stored size: 993 Bytes

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  module Excellent

    module Checks

      module Rails

        # This check reports +ActiveRecord+ models that do not validate anything. Not validating anything in the model is usually not intended and has
        # most likely just been forgotten. For more information on validations and why to use them, see http://guides.rubyonrails.org/activerecord_validations_callbacks.html#why-use-validations.
        #
        # ==== Applies to
        #
        # * +ActiveRecord+ models
        class ValidationsCheck < Base

          def initialize(options = {}) #:nodoc:
            super
            @interesting_contexts = [Parsing::ClassContext]
          end

          def evaluate(context) #:nodoc:
            add_warning(context, '{{class}} does not validate any attributes.', { :class => context.full_name }) if context.active_record_model? && !context.validating?
          end

        end

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
excellent-2.1.1 lib/simplabs/excellent/checks/rails/validations_check.rb
excellent-2.1.0 lib/simplabs/excellent/checks/rails/validations_check.rb
excellent-2.0.1 lib/simplabs/excellent/checks/rails/validations_check.rb
excellent-2.0.0 lib/simplabs/excellent/checks/rails/validations_check.rb