Sha256: e0d9ae13f6707140040586b18b994988dfd81a1cae75e719d992e1a5fbc34797

Contents?: true

Size: 1.57 KB

Versions: 11

Compression:

Stored size: 1.57 KB

Contents

module Shoulda # :nodoc:
  module Matchers
    module ActiveModel # :nodoc:
      class ValidationMatcher # :nodoc:
        attr_reader :failure_message

        def initialize(attribute)
          @attribute = attribute
          @strict = false
        end

        def strict
          @strict = true
          self
        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 = allow_value_matcher(value, 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 = allow_value_matcher(value, message)

          if disallow.matches?(@subject)
            @failure_message = disallow.negative_failure_message
            false
          else
            @negative_failure_message = disallow.failure_message
            true
          end
        end

        def allow_value_matcher(value, message)
          matcher = AllowValueMatcher.
            new(value).
            for(@attribute).
            with_message(message)

          if strict?
            matcher.strict
          else
            matcher
          end
        end

        def strict?
          @strict
        end
      end
    end
  end
end

Version data entries

11 entries across 10 versions & 4 rubygems

Version Path
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.9.1.beta.3 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validation_matcher.rb
devise_sociable-0.1.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.9.1.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.9.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/validation_matcher.rb
shoulda-matchers-1.4.2 lib/shoulda/matchers/active_model/validation_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/active_model/validation_matcher.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/active_model/validation_matcher.rb
shoulda-matchers-1.4.1 lib/shoulda/matchers/active_model/validation_matcher.rb
shoulda-matchers-1.4.0 lib/shoulda/matchers/active_model/validation_matcher.rb