Class: Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher

Inherits:
ValidationMatcher
  • Object
show all
Includes:
Helpers
Defined in:
lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb

Instance Attribute Summary collapse

Attributes included from Qualifiers::IgnoringInterferenceByWriter

#ignore_interference_by_writer

Instance Method Summary collapse

Methods included from Helpers

#default_error_message, #format_validation_errors, #pretty_error_messages

Methods inherited from ValidationMatcher

#allow_blank, #description, #expects_custom_validation_message?, #expects_strict?, #failure_message, #failure_message_when_negated, #on, #strict, #with_message

Methods included from Qualifiers::IgnoringInterferenceByWriter

#ignoring_interference_by_writer

Constructor Details

#initialize(attribute) ⇒ ValidateConfirmationOfMatcher

Returns a new instance of ValidateConfirmationOfMatcher.



85
86
87
88
89
# File 'lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb', line 85

def initialize(attribute)
  super
  @expected_message = :confirmation
  @confirmation_attribute = "#{attribute}_confirmation"
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



83
84
85
# File 'lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb', line 83

def attribute
  @attribute
end

#confirmation_attributeObject (readonly)

Returns the value of attribute confirmation_attribute.



83
84
85
# File 'lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb', line 83

def confirmation_attribute
  @confirmation_attribute
end

Instance Method Details

#does_not_match?(subject) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
109
# File 'lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb', line 103

def does_not_match?(subject)
  super(subject)

  allows_different_value ||
    disallows_same_value ||
    disallows_missing_confirmation
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
# File 'lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb', line 95

def matches?(subject)
  super(subject)

  disallows_different_value &&
    allows_same_value &&
    allows_missing_confirmation
end

#simple_descriptionObject



91
92
93
# File 'lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb', line 91

def simple_description
  "validate that :#{@confirmation_attribute} matches :#{@attribute}"
end