Sha256: 5ca59592e2e748aecf56d7314ddba1f82614af383a275ac340ab291ccf65c818
Contents?: true
Size: 918 Bytes
Versions: 1
Compression:
Stored size: 918 Bytes
Contents
module Shoulda module Matchers module ActiveModel def validate_as_cpf(attr) ValidateAsCpfMatcher.new(attr) end class ValidateAsCpfMatcher < ValidationMatcher def initialize(attribute) @attribute = attribute end def description "validate #{@attribute} as a valid CPF number" end def failure_message "expected #{@attribute} to be validated as a valid CPF number" end def matches?(subject) super(subject) disallows_invalid_value and allows_valid_value and allows_nil_value end private def disallows_invalid_value disallows_value_of("123456") end def allows_valid_value allows_value_of("897.546.112-20") end def allows_nil_value allows_value_of(nil) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validates_cpf-0.1.1 | lib/shoulda-matchers/validate_as_cpf_matcher.rb |