Class: Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher
Instance Attribute Summary
#ignore_interference_by_writer
Instance Method Summary
collapse
#allow_blank, #description, #expects_custom_validation_message?, #expects_strict?, #failure_message, #failure_message_when_negated, #failure_reason, #on, #strict, #with_message
#ignoring_interference_by_writer
Constructor Details
Returns a new instance of ValidateExclusionOfMatcher.
146
147
148
149
150
151
|
# File 'lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb', line 146
def initialize(attribute)
super(attribute)
@expected_message = :exclusion
@array = nil
@range = nil
end
|
Instance Method Details
#does_not_match?(subject) ⇒ Boolean
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb', line 196
def does_not_match?(subject)
super(subject)
if @range
disallows_lower_value ||
allows_minimum_value ||
allows_maximum_value ||
disallows_higher_value
elsif @array
allows_any_values_in_array?
end
end
|
#in_array(array) ⇒ Object
153
154
155
156
|
# File 'lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb', line 153
def in_array(array)
@array = array
self
end
|
#in_range(range) ⇒ Object
158
159
160
161
162
163
|
# File 'lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb', line 158
def in_range(range)
@range = range
@minimum = range.first
@maximum = range.max
self
end
|
#matches?(subject) ⇒ Boolean
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb', line 183
def matches?(subject)
super(subject)
if @range
allows_lower_value &&
disallows_minimum_value &&
disallows_maximum_value &&
allows_higher_value
elsif @array
disallows_all_values_in_array?
end
end
|
#simple_description ⇒ Object
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb', line 165
def simple_description
if @range
"validate that :#{@attribute} lies outside the range " +
Shoulda::Matchers::Util.inspect_range(@range)
else
description = "validate that :#{@attribute}"
description <<
if @array.many?
" is neither #{inspected_array}"
else
" is not #{inspected_array}"
end
description
end
end
|