Sha256: 3ca28e556d5c396021116b473ccf4745a721c5b397dd19685aa9a8a7107d94b0

Contents?: true

Size: 1006 Bytes

Versions: 153

Compression:

Stored size: 1006 Bytes

Contents

module Shoulda # :nodoc:
  module ActiveRecord # :nodoc:
    module Matchers

      # 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

153 entries across 123 versions & 25 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/active_record/matchers/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-2.11.3/lib/shoulda/active_record/matchers/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-2.11.3/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
Flamefork-shoulda-2.10.1 lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
Flamefork-shoulda-2.10.2 lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.0 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.1 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.10 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.11 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.12 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.13 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.14 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.15 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.16 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.17 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.2 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.3 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.4 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb
auser-poolparty-1.3.5 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb