class Shoulda::Matchers::ActiveRecord::NormalizeMatcher
@private
Attributes
attributes[R]
failure_message[R]
failure_message_when_negated[R]
from_value[R]
to_value[R]
Public Class Methods
new(*attributes)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 81 def initialize(*attributes) @attributes = attributes end
Public Instance Methods
description()
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 85 def description %( normalize #{attributes.to_sentence(last_word_connector: ' and ')} from ‹#{from_value.inspect}› to ‹#{to_value.inspect}› ).squish end
does_not_match?(subject)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 108 def does_not_match?(subject) attributes.all? { |attribute| attribute_does_not_match?(subject, attribute) } end
from(value)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 92 def from(value) @from_value = value self end
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 104 def matches?(subject) attributes.all? { |attribute| attribute_matches?(subject, attribute) } end
to(value)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 98 def to(value) @to_value = value self end
Private Instance Methods
attribute_does_not_match?(subject, attribute)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 124 def attribute_does_not_match?(subject, attribute) return true unless normalize_attribute?(subject, attribute) @failure_message_when_negated = build_failure_message_when_negated(attribute) false end
attribute_matches?(subject, attribute)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 114 def attribute_matches?(subject, attribute) return true if normalize_attribute?(subject, attribute) @failure_message = build_failure_message( attribute, subject.class.normalize_value_for(attribute, from_value), ) false end
build_failure_message(attribute, attribute_value)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 135 def build_failure_message(attribute, attribute_value) %( Expected to normalize #{attribute.inspect} from ‹#{from_value.inspect}› to ‹#{to_value.inspect}› but it was normalized to ‹#{attribute_value.inspect}› ).squish end
build_failure_message_when_negated(attribute)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 142 def build_failure_message_when_negated(attribute) %( Expected to not normalize #{attribute.inspect} from ‹#{from_value.inspect}› to ‹#{to_value.inspect}› but it was normalized ).squish end
normalize_attribute?(subject, attribute)
click to toggle source
# File lib/shoulda/matchers/active_record/normalize_matcher.rb, line 131 def normalize_attribute?(subject, attribute) subject.class.normalize_value_for(attribute, from_value) == to_value end