class Shoulda::Matchers::ActiveModel::ValidateConfirmationOfMatcher

@private

Attributes

attribute[R]
confirmation_attribute[R]

Public Class Methods

new(attribute) click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 64
def initialize(attribute)
  super(attribute)
  @confirmation_attribute = "#{attribute}_confirmation"
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 74
def description
  "require #{@confirmation_attribute} to match #{@attribute}"
end
matches?(subject) click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 78
def matches?(subject)
  super(subject)
  @message ||= :confirmation

  disallows_different_value &&
    allows_same_value &&
    allows_missing_confirmation
end
with_message(message) click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 69
def with_message(message)
  @message = message if message
  self
end

Private Instance Methods

allows_missing_confirmation() click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 103
def allows_missing_confirmation
  set_confirmation(nil)
  allows_value_of('any value') do |matcher|
    qualify_matcher(matcher)
  end
end
allows_same_value() click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 96
def allows_same_value
  set_confirmation('same value')
  allows_value_of('same value') do |matcher|
    qualify_matcher(matcher)
  end
end
disallows_different_value() click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 89
def disallows_different_value
  set_confirmation('some value')
  disallows_value_of('different value') do |matcher|
    qualify_matcher(matcher)
  end
end
error_attribute() click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 124
def error_attribute
  RailsShim.validates_confirmation_of_error_attribute(self)
end
qualify_matcher(matcher) click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 110
def qualify_matcher(matcher)
  matcher.with_message(@message,
    against: error_attribute,
    values: { attribute: attribute }
  )
end
set_confirmation(val) click to toggle source
# File lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb, line 117
def set_confirmation(val)
  setter = :"#{@confirmation_attribute}="
  if @subject.respond_to?(setter)
    @subject.__send__(setter, val)
  end
end