Sha256: e2d05e158cb4c78d6f4624be2a035004d539a4bf76bc700f11ec0a8ba56577c5

Contents?: true

Size: 1.3 KB

Versions: 39

Compression:

Stored size: 1.3 KB

Contents

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

      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

39 entries across 39 versions & 10 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.1 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.10 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.11 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.12 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.13 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.14 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.15 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.16 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.17 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.2 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.3 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.4 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.5 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.6 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.7 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
auser-poolparty-1.3.8 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
fairchild-poolparty-1.3.17 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
fairchild-poolparty-1.3.5 vendor/gems/shoulda/lib/shoulda/active_record/matchers/validation_matcher.rb
iGEL-shoulda-2.10.2 lib/shoulda/active_record/matchers/validation_matcher.rb