Sha256: 518ba8c36bc53e247e9529e2e8cefca479d054359f914c6b22cb7abfa5dd7ca0
Contents?: true
Size: 1.05 KB
Versions: 9
Compression:
Stored size: 1.05 KB
Contents
module Mongoid module Matchers module Validations class ValidateAcceptanceMatcher < HaveValidationMatcher def initialize(field) super(field, :acceptance) end def accept_with(value) @accepted = value self end def matches?(subject) return false unless @result = super(subject) check_accepted_value if @accepted @result end def description desc = [] desc << " accept with #{@accepted.inspect}" if @accepted super << desc.to_sentence end private def check_accepted_value actual = @validator.options[:accept] if actual == @accepted @positive_message << " accept with #{actual.inspect}" else @negative_message << " accept with #{actual.inspect}" @result = false end end end def validate_acceptance_of(field) ValidateAcceptanceMatcher.new(field) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems