Sha256: 0b98a60ae31d482d02cc75b5214837b90aec6b85fd6e149e63eec969c081b01b

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

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

      class ValidationMatcher # :nodoc:

        attr_reader :failure_message

        def initialize(attribute)
          @attribute = attribute
        end

        def negative_failure_message
          @negative_failure_message || @failure_message
        end

        def matches?(subject)
          @subject = subject
          false
        end

        private

        def allows_value_of(value, message = nil)
          allow = AllowValueMatcher.
            new(value).
            for(@attribute).
            with_message(message)
          if allow.matches?(@subject)
            @negative_failure_message = allow.failure_message
            true
          else
            @failure_message = allow.negative_failure_message
            false
          end
        end

        def disallows_value_of(value, message = nil)
          disallow = AllowValueMatcher.
            new(value).
            for(@attribute).
            with_message(message)
          if disallow.matches?(@subject)
            @failure_message = disallow.negative_failure_message
            false
          else
            @negative_failure_message = disallow.failure_message
            true
          end
        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/validation_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/validation_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/validation_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.6.2 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.6.1 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.6.0 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.5.4 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.5.3 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.5.2 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.5.1 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/active_model/validation_matcher.rb
shoulda-matchers-1.0.0 lib/shoulda/matchers/active_model/validation_matcher.rb
shoulda-matchers-1.0.0.beta3 lib/shoulda/matchers/active_model/validation_matcher.rb
yetanothernguyen-shoulda-matchers-1.0.0.beta3 lib/shoulda/matchers/active_model/validation_matcher.rb