Class: Shoulda::Matchers::ActiveModel::NumericalityMatchers::ComparisonMatcher
- Inherits:
-
ValidationMatcher
- Object
- ValidationMatcher
- Shoulda::Matchers::ActiveModel::NumericalityMatchers::ComparisonMatcher
show all
- Defined in:
- lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb
Constant Summary
collapse
- ERROR_MESSAGES =
{
:> => {
label: :greater_than,
assertions: [false, false, true],
},
:>= => {
label: :greater_than_or_equal_to,
assertions: [false, true, true],
},
:< => {
label: :less_than,
assertions: [true, false, false],
},
:<= => {
label: :less_than_or_equal_to,
assertions: [true, true, false],
},
:== => {
label: :equal_to,
assertions: [false, true, false],
},
:!= => {
label: :other_than,
assertions: [true, false, true],
},
}.freeze
Instance Attribute Summary
#ignore_interference_by_writer
Instance Method Summary
collapse
#allow_blank, #description, #does_not_match?, #expects_strict?, #on, #strict
#ignoring_interference_by_writer
Constructor Details
#initialize(numericality_matcher, value, operator) ⇒ ComparisonMatcher
Returns a new instance of ComparisonMatcher.
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 34
def initialize(numericality_matcher, value, operator)
super(nil)
unless numericality_matcher.respond_to? :diff_to_compare
raise ArgumentError, 'numericality_matcher is invalid'
end
@numericality_matcher = numericality_matcher
@value = value
@operator = operator
@message = ERROR_MESSAGES[operator][:label]
end
|
Instance Method Details
#comparison_description ⇒ Object
86
87
88
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 86
def comparison_description
"#{comparison_expectation} #{@value}"
end
|
#expects_custom_validation_message? ⇒ Boolean
69
70
71
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 69
def expects_custom_validation_message?
@expects_custom_validation_message
end
|
#failure_message ⇒ Object
78
79
80
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 78
def failure_message
last_failing_submatcher.failure_message
end
|
#failure_message_when_negated ⇒ Object
82
83
84
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 82
def failure_message_when_negated
last_failing_submatcher.failure_message_when_negated
end
|
#for(attribute) ⇒ Object
58
59
60
61
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 58
def for(attribute)
@attribute = attribute
self
end
|
#matches?(subject) ⇒ Boolean
73
74
75
76
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 73
def matches?(subject)
@subject = subject
all_bounds_correct?
end
|
#simple_description ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 46
def simple_description
description = ''
if expects_strict?
description << ' strictly'
end
description +
"disallow :#{attribute} from being a number that is not " +
"#{comparison_expectation} #{@value}"
end
|
#with_message(message) ⇒ Object
63
64
65
66
67
|
# File 'lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb', line 63
def with_message(message)
@expects_custom_validation_message = true
@message = message
self
end
|