Class: Shoulda::Matchers::ActiveModel::ValidateCnsMatcher

Inherits:
ValidationMatcher
  • Object
show all
Defined in:
lib/cns_brazil/validate_cns_matcher.rb

Constant Summary collapse

ALLOW_VALUES =
[
  '166947669770008',
  222_491_445_220_008,
  '736 3347 8546 0000',
  '807769250350009',
  954_180_214_890_002
].freeze
DISALLOW_VALUES =
%w[12345678912314 1234567891234516].freeze

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ ValidateCnsMatcher

Returns a new instance of ValidateCnsMatcher.



23
24
25
26
# File 'lib/cns_brazil/validate_cns_matcher.rb', line 23

def initialize(attribute)
  super(attribute)
  @options = {}
end

Instance Method Details

#descriptionObject



28
29
30
31
32
33
34
# File 'lib/cns_brazil/validate_cns_matcher.rb', line 28

def description
  message = 'requires a valid CNS'

  message += ' included blank' if expects_to_allow_blank?

  message
end

#does_not_match?(subject) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/cns_brazil/validate_cns_matcher.rb', line 46

def does_not_match?(subject)
  super(subject)

  DISALLOW_VALUES.each { |value| disallows_value_of(value) }
end

#failure_messageObject



36
37
38
# File 'lib/cns_brazil/validate_cns_matcher.rb', line 36

def failure_message
  'does not require a valid CNS'
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/cns_brazil/validate_cns_matcher.rb', line 40

def matches?(subject)
  super(subject)

  ALLOW_VALUES.each { |value| allows_value_of(value) }
end