Sha256: 60bf990cc7eb40ae0f40a6219a8404c506689dcb66b050fbf16803d739a43cde
Contents?: true
Size: 975 Bytes
Versions: 1
Compression:
Stored size: 975 Bytes
Contents
require "shoulda-matchers" module Shoulda module Matchers module ActiveModel def validate_as_telephone(attr) ValidateAsTelephoneMatcher.new(attr) end class ValidateAsTelephoneMatcher < ValidationMatcher def initialize(attribute) @attribute = attribute end def description "validate #{@attribute} as a valid Telephone number" end def failure_message "expected #{@attribute} to be validated as a valid Telephone 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("(11)2222-3333") 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_telephone-0.1.0 | lib/validates_telephone/shoulda-matchers/validate_as_telephone_matcher.rb |