Sha256: effed3abd342849cae0359d28e41ff925ea81c12aca05b5ace73caa0f91d5947

Contents?: true

Size: 1005 Bytes

Versions: 14

Compression:

Stored size: 1005 Bytes

Contents

module Shoulda # :nodoc:
  module Matchers
    module ActiveModel # :nodoc:

      # Ensure that the attribute is numeric
      #
      # Options:
      # * <tt>with_message</tt> - value the test expects to find in
      #   <tt>errors.on(:attribute)</tt>. Regexp or string.  Defaults to the
      #   translation for <tt>:not_a_number</tt>.
      #
      # Example:
      #   it { should validate_numericality_of(:age) }
      #
      def validate_numericality_of(attr)
        ValidateNumericalityOfMatcher.new(attr)
      end

      class ValidateNumericalityOfMatcher < ValidationMatcher # :nodoc:

        def with_message(message)
          @expected_message = message if message
          self
        end

        def matches?(subject)
          super(subject)
          @expected_message ||= :not_a_number
          disallows_value_of('abcd', @expected_message)
        end

        def description
          "only allow numeric values for #{@attribute}"
        end
      end

    end
  end
end

Version data entries

14 entries across 11 versions & 4 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
challah-0.6.2 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
challah-0.6.1 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
challah-0.6.0 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
challah-0.5.4 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
challah-0.5.3 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
challah-0.5.2 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
challah-0.5.1 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
shoulda-matchers-1.0.0 lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
shoulda-matchers-1.0.0.beta3 lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb
yetanothernguyen-shoulda-matchers-1.0.0.beta3 lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb