minitest-sequel 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,549 +1,1167 @@
1
- # require "minitest/sequel"
1
+ # frozen_string_literal: false
2
+
3
+ require 'minitest/spec'
2
4
 
3
5
  # reopening to add validations functionality
4
- module Minitest::Assertions
5
-
6
- # Test for validating presence of a model attribute
7
- #
8
- # it { assert_validates_presence(model, :title) }
9
- # it { model.must_validate_presence_of(:title, { message: '...' }) }
10
- #
11
- def assert_validates_presence(obj, attribute, opts = {}, msg = nil)
12
- assert_validates(obj, :presence, attribute, opts, msg)
13
- end
14
- alias_method :assert_validates_presence_of, :assert_validates_presence
15
-
16
- # Test for validating the length of a model's attribute.
17
- #
18
- # Available options:
19
- #
20
- # * :message - The message to use (no default, overrides :nil_message, :too_long, :too_short, and :wrong_length options if present)
21
- # * :nil_message - The message to use use if :maximum option is used and the value is nil (default: 'is not present')
22
- #
23
- # * :too_long - The message to use use if it the value is too long (default: 'is too long')
24
- #
25
- # * :too_short - The message to use use if it the value is too short (default: 'is too short')
26
- #
27
- # * :wrong_length - The message to use use if it the value is not valid (default: 'is the wrong length')
28
- #
29
- # Size related options:
30
- #
31
- # * :is - The exact size required for the value to be valid (no default)
32
- #
33
- # * :minimum - The minimum size allowed for the value (no default)
34
- #
35
- # * :maximum - The maximum size allowed for the value (no default)
36
- #
37
- # * :within - The array/range that must include the size of the value for it to be valid (no default)
38
- #
39
- #
40
- # it { assert_validates_length(model, :title, { maximum: 12 }) }
41
- # it { model.must_validate_length_of(:title, { within: 4..12 }) }
42
- #
43
- def assert_validates_length(obj, attribute, opts = {}, msg = nil)
44
- assert_validates(obj, :length, attribute, opts, msg)
45
- end
46
- alias_method :assert_validates_length_of, :assert_validates_length
47
-
48
- # Test for validating the exact length of a model's attribute.
49
- #
50
- # it { assert_validates_exact_length(model, :title, 12, { message: '...' }) }
51
- # it { model.must_validate_exact_length_of(:title, 12, { message: '...' }) }
52
- #
53
- def assert_validates_exact_length(obj, attribute, exact_length, opts = {}, msg = nil)
54
- opts.merge!(is: exact_length)
55
- assert_validates(obj, :length, attribute, opts, msg)
56
- end
57
- alias_method :assert_validates_exact_length_of, :assert_validates_exact_length
58
-
59
- # Test for validating the exact length of a model's attribute.
60
- #
61
- # it { assert_validates_length_range(model, :title, 4..12, { message: '...' }) }
62
- # it { model.must_validate_length_range_of(:title, 4..12, { message: '...' }) }
63
- #
64
- def assert_validates_length_range(obj, attribute, range, opts = {}, msg = nil)
65
- opts.merge!(within: range)
66
- assert_validates(obj, :length, attribute, opts, msg)
67
- end
68
- alias_method :assert_validates_length_range_of, :assert_validates_length_range
69
-
70
- # Test for validating the maximum length of a model's attribute.
71
- #
72
- # it { assert_validates_max_length(model, :title, 12, { message: '...' }) }
73
- # it { model.must_validate_max_length_of(:title, 12, { message: '...' }) }
74
- #
75
- def assert_validates_max_length(obj, attribute, max_length, opts = {}, msg = nil)
76
- opts.merge!(maximum: max_length)
77
- assert_validates(obj, :length, attribute, opts, msg)
78
- end
79
- alias_method :assert_validates_max_length_of, :assert_validates_max_length
80
-
81
- # Test for validating the minimum length of a model's attribute.
82
- #
83
- # it { assert_validates_min_length(model, :title, 12, { message: '...' }) }
84
- # it { model.must_validate_min_length_of(:title, 12, { message: '...' }) }
85
- #
86
- def assert_validates_min_length(obj, attribute, min_length, opts = {}, msg = nil)
87
- opts.merge!(minimum: min_length)
88
- assert_validates(obj, :length, attribute, opts, msg)
89
- end
90
- alias_method :assert_validates_min_length_of, :assert_validates_min_length
91
-
92
- # Test for validating the format of a model's attribute with a regexp.
93
- #
94
- # it { assert_validates_format(model, :title, 12, { with: /[a-z+]/ }) }
95
- # it { model.must_validate_format_of(:title, 12, { with: /[a-z]+/ }) }
96
- #
97
- def assert_validates_format(obj, attribute, opts = {}, msg = nil)
98
- assert_validates(obj, :format, attribute, opts, msg)
99
- end
100
- alias_method :assert_validates_format_of, :assert_validates_format
101
-
102
- # Test for validating that a model's attribute is within a specified range or set of values.
103
- #
104
- # it { assert_validates_inclusion(model, :status, { in: [:a, :b, :c] }) }
105
- # it { model.must_validate_inclusion_of(:status, { in: [:a, :b, :c] }) }
106
- #
107
- def assert_validates_inclusion(obj, attribute, opts = {}, msg = nil)
108
- assert_validates(obj, :inclusion, attribute, opts, msg)
109
- end
110
- alias_method :assert_validates_inclusion_of, :assert_validates_inclusion
111
-
112
- # Test for validating that a a model's attribute is an integer.
113
- #
114
- # it { assert_validates_integer(model, :author_id, { message: '...' }) }
115
- # it { model.must_validate_integer_of(:author_id, { message: '...' }) }
116
- #
117
- def assert_validates_integer(obj, attribute, opts = {}, msg = nil)
118
- opts.merge!(only_integer: true)
119
- assert_validates(obj, :numericality, attribute, opts, msg)
120
- end
6
+ module Minitest
7
+ # add support for Assert syntax
8
+ # rubocop:disable Metrics/ModuleLength
9
+ module Assertions
10
+ # Test for validating presence of a model attribute
11
+ #
12
+ # This method checks if the specified attribute of the given object
13
+ # has a presence validation. It can be used in both assertion and
14
+ # expectation styles.
15
+ #
16
+ # @param obj [Object] The model object to test
17
+ # @param attribute [Symbol] The attribute to check for presence validation
18
+ # @param opts [Hash] Additional options for the validation (default: {})
19
+ # @param msg [String] Custom error message (default: nil)
20
+ #
21
+ # @example Using assertion style
22
+ # assert_validates_presence(model, :title)
23
+ #
24
+ # @example Using expectation style
25
+ # model.must_validate_presence_of(:title)
26
+ #
27
+ # @example With custom error message
28
+ # assert_validates_presence(model, :title, { message: 'Title cannot be blank' })
29
+ #
30
+ def assert_validates_presence(obj, attribute, opts = {}, msg = nil)
31
+ assert_validates(obj, :presence, attribute, opts, msg)
32
+ end
33
+ alias assert_validates_presence_of assert_validates_presence
121
34
 
122
- # Test for validating that a model's attribute is numeric (number).
123
- #
124
- # it { assert_validates_numericality(model, :author_id, { message: '...' }) }
125
- # it { model.must_validate_numericality_of(:author_id, { message: '...' }) }
126
- #
127
- def assert_validates_numericality(obj, attribute, opts = {}, msg = nil)
128
- assert_validates(obj, :numericality, attribute, opts, msg)
129
- end
130
- alias_method :assert_validates_numericality_of, :assert_validates_numericality
131
-
132
- # Test for validating that a model's attribute is unique.
133
- #
134
- # it { assert_validates_uniqueness(model, :urlslug, { message: '...' }) }
135
- # it { model.must_validate_uniqueness_of(:urlslug, { message: '...' }) }
136
- #
137
- def assert_validates_uniqueness(obj, attribute, opts = {}, msg = nil)
138
- assert_validates(obj, :uniqueness, attribute, opts, msg)
139
- end
140
- alias_method :assert_validates_uniqueness_of, :assert_validates_uniqueness
35
+ # Test for validating the length of a model's attribute.
36
+ #
37
+ # This method checks if the specified attribute of the given object
38
+ # has a length validation. It can be used in both assertion and
39
+ # expectation styles.
40
+ #
41
+ # @param obj [Object] The model object to test
42
+ # @param attribute [Symbol] The attribute to check for length validation
43
+ # @param opts [Hash] Additional options for the validation (default: {})
44
+ # @param msg [String] Custom error message (default: nil)
45
+ #
46
+ # Available options:
47
+ #
48
+ # * :message - The message to use (no default, overrides :nil_message, :too_long,
49
+ # :too_short, and :wrong_length options if present)
50
+ # * :nil_message - The message to use if :maximum option is used and the value is nil
51
+ # (default: 'is not present')
52
+ # * :too_long - The message to use if the value is too long (default: 'is too long')
53
+ # * :too_short - The message to use if the value is too short (default: 'is too short')
54
+ # * :wrong_length - The message to use if the value is not valid
55
+ # (default: 'is the wrong length')
56
+ #
57
+ # Size related options:
58
+ #
59
+ # * :is - The exact size required for the value to be valid (no default)
60
+ # * :minimum - The minimum size allowed for the value (no default)
61
+ # * :maximum - The maximum size allowed for the value (no default)
62
+ # * :within - The array/range that must include the size of value for the value (no default)
63
+ #
64
+ # @example Using assertion style
65
+ # assert_validates_length(model, :title, { maximum: 12 })
66
+ #
67
+ # @example Using expectation style
68
+ # model.must_validate_length_of(:title, { within: 4..12 })
69
+ #
70
+ def assert_validates_length(obj, attribute, opts = {}, msg = nil)
71
+ assert_validates(obj, :length, attribute, opts, msg)
72
+ end
73
+ alias assert_validates_length_of assert_validates_length
74
+
75
+ # Test for validating the exact length of a model's attribute.
76
+ #
77
+ # This method checks if the specified attribute of the given object
78
+ # has a length validation for an exact length. It can be used in both
79
+ # assertion and expectation styles.
80
+ #
81
+ # @param obj [Object] The model object to test
82
+ # @param attribute [Symbol] The attribute to check for exact length validation
83
+ # @param exact_length [Integer] The exact length to validate against
84
+ # @param opts [Hash] Additional options for the validation (default: {})
85
+ # @param msg [String] Custom error message (default: nil)
86
+ #
87
+ # @example Using assertion style
88
+ # assert_validates_exact_length(
89
+ # model,
90
+ # :title,
91
+ # 12,
92
+ # { message: 'Must be exactly 12 characters' }
93
+ # )
94
+ #
95
+ # @example Using expectation style
96
+ # model.must_validate_exact_length_of(
97
+ # :title,
98
+ # 12,
99
+ # { message: 'Must be exactly 12 characters' }
100
+ # )
101
+ #
102
+ def assert_validates_exact_length(obj, attribute, exact_length, opts = {}, msg = nil)
103
+ opts[:is] = exact_length
104
+ assert_validates(obj, :length, attribute, opts, msg)
105
+ end
106
+ alias assert_validates_exact_length_of assert_validates_exact_length
141
107
 
142
- # Validates acceptance of an attribute. Just checks that the value is equal to the :accept option. This method is unique in that :allow_nil is assumed to be true instead of false.
108
+ # Test for validating the length range of a model's attribute.
109
+ #
110
+ # This method checks if the specified attribute of the given object
111
+ # has a length validation within a specified range. It can be used in both
112
+ # assertion and expectation styles.
113
+ #
114
+ # @param obj [Object] The model object to test
115
+ # @param attribute [Symbol] The attribute to check for length range validation
116
+ # @param range [Range] The range of acceptable lengths
117
+ # @param opts [Hash] Additional options for the validation (default: {})
118
+ # @param msg [String] Custom error message (default: nil)
119
+ #
120
+ # @example Using assertion style
121
+ # assert_validates_length_range(
122
+ # model,
123
+ # :title,
124
+ # 4..12,
125
+ # { message: 'Title must be between 4 and 12 characters' }
126
+ # )
127
+ #
128
+ # @example Using expectation style
129
+ # model.must_validate_length_range_of(
130
+ # :title,
131
+ # 4..12,
132
+ # { message: 'Title must be between 4 and 12 characters' }
133
+ # )
134
+ #
135
+ def assert_validates_length_range(obj, attribute, range, opts = {}, msg = nil)
136
+ opts[:within] = range
137
+ assert_validates(obj, :length, attribute, opts, msg)
138
+ end
139
+ alias assert_validates_length_range_of assert_validates_length_range
143
140
 
144
- # Test for validating the acceptance of a model's attribute.
145
- #
146
- # it { assert_validates_acceptance(Order.new, :toc, { message: '...' }) }
147
- # it { model.must_validate_acceptance_of(:toc, { message: '...' }) }
148
- #
149
- def assert_validates_acceptance(obj, attribute, opts = {}, msg = nil)
150
- assert_validates(obj, :acceptance, attribute, opts, msg)
151
- end
152
- alias_method :assert_validates_acceptance_of, :assert_validates_acceptance
153
-
154
- # Test for validating the confirmation of a model's attribute.
155
- #
156
- # it { assert_validates_confirmation(User.new, :password, { message: '...' }) }
157
- # it { User.new.must_validate_confirmation_of(:password, { message: '...' }) }
158
- #
159
- def assert_validates_confirmation(obj, attribute, opts = {}, msg = nil)
160
- assert_validates(obj, :confirmation, attribute, opts, msg)
161
- end
162
- alias_method :assert_validates_confirmation_of, :assert_validates_confirmation
141
+ # Test for validating the maximum length of a model's attribute.
142
+ #
143
+ # This method checks if the specified attribute of the given object
144
+ # has a length validation with a maximum value. It can be used in both
145
+ # assertion and expectation styles.
146
+ #
147
+ # @param obj [Object] The model object to test
148
+ # @param attribute [Symbol] The attribute to check for maximum length validation
149
+ # @param max_length [Integer] The maximum length to validate against
150
+ # @param opts [Hash] Additional options for the validation (default: {})
151
+ # @param msg [String] Custom error message (default: nil)
152
+ #
153
+ # @example Using assertion style
154
+ # assert_validates_max_length(model, :title, 12, { message: 'Title is too long' })
155
+ #
156
+ # @example Using expectation style
157
+ # model.must_validate_max_length_of(:title, 12, { message: 'Title is too long' })
158
+ #
159
+ def assert_validates_max_length(obj, attribute, max_length, opts = {}, msg = nil)
160
+ opts[:maximum] = max_length
161
+ assert_validates(obj, :length, attribute, opts, msg)
162
+ end
163
+ alias assert_validates_max_length_of assert_validates_max_length
163
164
 
164
- # Base test for validations of a model, used mainly as a shortcut for other assertions
165
- def assert_validates(obj, validation_type, attribute, opts = {}, msg = nil)
166
- msg = msg.nil? ? "" : "#{msg}\n"
167
- err_msg = []
168
- conf_msg = []
169
- unless obj.respond_to?(attribute)
170
- assert(false, "Column :#{attribute} is not defined in #{obj.class}")
165
+ # Test for validating the minimum length of a model's attribute.
166
+ #
167
+ # This method checks if the specified attribute of the given object
168
+ # has a length validation with a minimum value. It can be used in both
169
+ # assertion and expectation styles.
170
+ #
171
+ # @param obj [Object] The model object to test
172
+ # @param attribute [Symbol] The attribute to check for minimum length validation
173
+ # @param min_length [Integer] The minimum length to validate against
174
+ # @param opts [Hash] Additional options for the validation (default: {})
175
+ # @param msg [String] Custom error message (default: nil)
176
+ #
177
+ # @example Using assertion style
178
+ # assert_validates_min_length(model, :title, 12, { message: 'Title is too short' })
179
+ #
180
+ # @example Using expectation style
181
+ # model.must_validate_min_length_of(:title, 12, { message: 'Title is too short' })
182
+ #
183
+ def assert_validates_min_length(obj, attribute, min_length, opts = {}, msg = nil)
184
+ opts[:minimum] = min_length
185
+ assert_validates(obj, :length, attribute, opts, msg)
171
186
  end
187
+ alias assert_validates_min_length_of assert_validates_min_length
172
188
 
173
- msg << "Expected #{obj.class} to validate :#{validation_type} for :#{attribute} column"
189
+ # Test for validating the format of a model's attribute with a regexp.
190
+ #
191
+ # This method checks if the specified attribute of the given object
192
+ # has a format validation with the provided regular expression. It can be used
193
+ # in both assertion and expectation styles.
194
+ #
195
+ # @param obj [Object] The model object to test
196
+ # @param attribute [Symbol] The attribute to check for format validation
197
+ # @param opts [Hash] Additional options for the validation (default: {})
198
+ # @param msg [String] Custom error message (default: nil)
199
+ #
200
+ # @option opts [Regexp] :with The regular expression to validate against (required)
201
+ #
202
+ # @example Using assertion style
203
+ # assert_validates_format(model, :title, { with: /[a-z]+/ })
204
+ #
205
+ # @example Using expectation style
206
+ # model.must_validate_format_of(:title, { with: /[a-z]+/ })
207
+ #
208
+ # @example With custom error message
209
+ # assert_validates_format(
210
+ # model,
211
+ # :title,
212
+ # { with: /[a-z]+/, message: 'must contain only lowercase letters' }
213
+ # )
214
+ #
215
+ def assert_validates_format(obj, attribute, opts = {}, msg = nil)
216
+ assert_validates(obj, :format, attribute, opts, msg)
217
+ end
218
+ alias assert_validates_format_of assert_validates_format
174
219
 
175
- if _validated_model?(obj)
220
+ # Test for validating that a model's attribute is within a specified range or set of values.
221
+ #
222
+ # This method checks if the specified attribute of the given object
223
+ # has an inclusion validation with the provided set of values. It can be used
224
+ # in both assertion and expectation styles.
225
+ #
226
+ # @param obj [Object] The model object to test
227
+ # @param attribute [Symbol] The attribute to check for inclusion validation
228
+ # @param opts [Hash] Additional options for the validation (default: {})
229
+ # @param msg [String] Custom error message (default: nil)
230
+ #
231
+ # @option opts [Array, Range] :in The set of valid values (required)
232
+ #
233
+ # @example Using assertion style
234
+ # assert_validates_inclusion(model, :status, { in: [:a, :b, :c] })
235
+ #
236
+ # @example Using expectation style
237
+ # model.must_validate_inclusion_of(:status, { in: [:a, :b, :c] })
238
+ #
239
+ # @example With custom error message
240
+ # assert_validates_inclusion(
241
+ # model,
242
+ # :status,
243
+ # { in: [:a, :b, :c], message: 'must be a valid status' }
244
+ # )
245
+ #
246
+ def assert_validates_inclusion(obj, attribute, opts = {}, msg = nil)
247
+ assert_validates(obj, :inclusion, attribute, opts, msg)
248
+ end
249
+ alias assert_validates_inclusion_of assert_validates_inclusion
176
250
 
177
- if _validated_column?(obj, attribute)
251
+ # Test for validating that a model's attribute is an integer.
252
+ #
253
+ # This method checks if the specified attribute of the given object
254
+ # has a numericality validation with the 'only_integer' option set to true.
255
+ # It can be used in both assertion and expectation styles.
256
+ #
257
+ # @param obj [Object] The model object to test
258
+ # @param attribute [Symbol] The attribute to check for integer validation
259
+ # @param opts [Hash] Additional options for the validation (default: {})
260
+ # @param msg [String] Custom error message (default: nil)
261
+ #
262
+ # @example Using assertion style
263
+ # assert_validates_integer(model, :author_id, { message: 'must be an integer' })
264
+ #
265
+ # @example Using expectation style
266
+ # model.must_validate_integer_of(:author_id, { message: 'must be an integer' })
267
+ #
268
+ def assert_validates_integer(obj, attribute, opts = {}, msg = nil)
269
+ opts[:only_integer] = true
270
+ assert_validates(obj, :numericality, attribute, opts, msg)
271
+ end
178
272
 
179
- # checks if the model column is validated by the validation type
180
- if _validated_with_validation_type?(obj, attribute, validation_type)
181
- matching = true
273
+ # Test for validating that a model's attribute is numeric (number).
274
+ #
275
+ # This method checks if the specified attribute of the given object
276
+ # has a numericality validation. It can be used in both assertion and
277
+ # expectation styles.
278
+ #
279
+ # @param obj [Object] The model object to test
280
+ # @param attribute [Symbol] The attribute to check for numericality validation
281
+ # @param opts [Hash] Additional options for the validation (default: {})
282
+ # @param msg [String] Custom error message (default: nil)
283
+ #
284
+ # @example Using assertion style
285
+ # assert_validates_numericality(model, :price, { greater_than: 0 })
286
+ #
287
+ # @example Using expectation style
288
+ # model.must_validate_numericality_of(:price, { less_than_or_equal_to: 1000 })
289
+ #
290
+ # @example With custom error message
291
+ # assert_validates_numericality(
292
+ # model,
293
+ # :quantity,
294
+ # { only_integer: true, message: 'must be a whole number' }
295
+ # )
296
+ #
297
+ def assert_validates_numericality(obj, attribute, opts = {}, msg = nil)
298
+ assert_validates(obj, :numericality, attribute, opts, msg)
299
+ end
300
+ alias assert_validates_numericality_of assert_validates_numericality
182
301
 
183
- # bail out if options provided are invalid
184
- val_opts = _valid_validation_options(validation_type)
302
+ # Test for validating that a model's attribute is unique.
303
+ #
304
+ # This method checks if the specified attribute of the given object
305
+ # has a uniqueness validation. It can be used in both assertion and
306
+ # expectation styles.
307
+ #
308
+ # @param obj [Object] The model object to test
309
+ # @param attribute [Symbol] The attribute to check for uniqueness validation
310
+ # @param opts [Hash] Additional options for the validation (default: {})
311
+ # @param msg [String] Custom error message (default: nil)
312
+ #
313
+ # @example Using assertion style
314
+ # assert_validates_uniqueness(model, :urlslug, { message: 'must be unique' })
315
+ #
316
+ # @example Using expectation style
317
+ # model.must_validate_uniqueness_of(:urlslug, { case_sensitive: false })
318
+ #
319
+ # @example With custom error message
320
+ # assert_validates_uniqueness(
321
+ # model,
322
+ # :email,
323
+ # { scope: :account_id, message: 'already taken for this account' }
324
+ # )
325
+ #
326
+ def assert_validates_uniqueness(obj, attribute, opts = {}, msg = nil)
327
+ assert_validates(obj, :uniqueness, attribute, opts, msg)
328
+ end
329
+ alias assert_validates_uniqueness_of assert_validates_uniqueness
185
330
 
186
- invalid_opts = opts.keys.reject { |o| val_opts.include?(o) }
187
- unless invalid_opts.empty?
188
- msg << ", but the following invalid option(s) was found: { "
189
- invalid_opts.each { |o| msg << "#{o.inspect}; " }
190
- msg << " }. Valid options are: #{val_opts.inspect}"
191
- assert(false, msg)
192
- end
331
+ # Validates acceptance of an attribute. Just checks that the value is equal to the :accept
332
+ # option. This method is unique in that :allow_nil is assumed to be true instead of false.
333
+
334
+ # Test for validating the acceptance of a model's attribute.
335
+ #
336
+ # This method checks if the specified attribute of the given object
337
+ # has an acceptance validation. It can be used in both assertion and
338
+ # expectation styles.
339
+ #
340
+ # @param obj [Object] The model object to test
341
+ # @param attribute [Symbol] The attribute to check for acceptance validation
342
+ # @param opts [Hash] Additional options for the validation (default: {})
343
+ # @param msg [String] Custom error message (default: nil)
344
+ #
345
+ # @example Using assertion style
346
+ # assert_validates_acceptance(
347
+ # Order.new,
348
+ # :toc,
349
+ # { message: 'You must accept the terms and conditions' }
350
+ # )
351
+ #
352
+ # @example Using expectation style
353
+ # model.must_validate_acceptance_of(:toc, { accept: 'yes' })
354
+ #
355
+ # @note The acceptance validation is typically used for checkboxes in web forms
356
+ # where the user needs to accept terms of service.
357
+ #
358
+ def assert_validates_acceptance(obj, attribute, opts = {}, msg = nil)
359
+ assert_validates(obj, :acceptance, attribute, opts, msg)
360
+ end
361
+ alias assert_validates_acceptance_of assert_validates_acceptance
362
+
363
+ # Test for validating the confirmation of a model's attribute.
364
+ #
365
+ # This method checks if the specified attribute of the given object
366
+ # has a confirmation validation. It can be used in both assertion and
367
+ # expectation styles.
368
+ #
369
+ # @param obj [Object] The model object to test
370
+ # @param attribute [Symbol] The attribute to check for confirmation validation
371
+ # @param opts [Hash] Additional options for the validation (default: {})
372
+ # @param msg [String] Custom error message (default: nil)
373
+ #
374
+ # @example Using assertion style
375
+ # assert_validates_confirmation(User.new, :password, { message: 'Passwords do not match' })
376
+ #
377
+ # @example Using expectation style
378
+ # User.new.must_validate_confirmation_of(:password, { message: 'Passwords do not match' })
379
+ #
380
+ # @note The confirmation validation is typically used for password fields
381
+ # where the user needs to enter the same password twice.
382
+ #
383
+ def assert_validates_confirmation(obj, attribute, opts = {}, msg = nil)
384
+ assert_validates(obj, :confirmation, attribute, opts, msg)
385
+ end
386
+ alias assert_validates_confirmation_of assert_validates_confirmation
387
+
388
+ # Base test for validations of a model, used mainly as a shortcut for other assertions
389
+ #
390
+ # This method checks if the specified attribute of the given object has the expected
391
+ # validation type and options. It can be used to test various validation types such as
392
+ # ;presence, :format, :length, etc.
393
+ #
394
+ # @param obj [Object] The model object to test
395
+ # @param validation_type [Symbol] The type of validation to check
396
+ # (e.g., :presence, :format, :length)
397
+ # @param attribute [Symbol] The attribute to check for validation
398
+ # @param opts [Hash] Additional options for the validation (default: {})
399
+ # @param msg [String] Custom error message (default: nil)
400
+ #
401
+ # @example Testing presence validation
402
+ # assert_validates(User.new, :presence, :name, { message: "can't be blank" })
403
+ #
404
+ # @example Testing length validation
405
+ # assert_validates(Post.new, :length, :title, { minimum: 5, maximum: 100 })
406
+ #
407
+ # @raise [Minitest::Assertion] If the validation does not match the expected criteria
408
+ #
409
+ # rubocop:disable Metrics/*
410
+ def assert_validates(obj, validation_type, attribute, opts = {}, msg = nil)
411
+ msg = msg.nil? ? '' : "#{msg}\n"
412
+ err_msg = []
413
+ conf_msg = []
414
+
415
+ unless obj.respond_to?(attribute)
416
+ assert(false, "Column :#{attribute} is not defined in #{obj.class}")
417
+ end
418
+
419
+ msg << "Expected #{obj.class} to validate :#{validation_type} for :#{attribute} column"
420
+
421
+ if _validated_model?(obj)
422
+ if _validated_column?(obj, attribute)
423
+ # checks if the model column is validated by the validation type
424
+ if _validated_with_validation_type?(obj, attribute, validation_type)
425
+ matching = true
426
+
427
+ # bail out if options provided are invalid
428
+ val_opts = _valid_validation_options(validation_type)
429
+
430
+ invalid_opts = opts.keys.reject { |o| val_opts.include?(o) }
431
+ unless invalid_opts.empty?
432
+ msg << ', but the following invalid option(s) was found: { '
433
+ invalid_opts.each { |o| msg << "#{o.inspect}; " }
434
+ msg << " }. Valid options are: #{val_opts.inspect}"
435
+ assert(false, msg)
436
+ end
437
+
438
+ h = _validation_types_hash_for_column(obj, attribute)
439
+ _available_validation_options.each do |ov|
440
+ next if opts[ov].nil?
193
441
 
194
- h = _validation_types_hash_for_column(obj, attribute)
195
- _available_validation_options.each do |ov|
196
- unless opts[ov].nil?
197
442
  expected = (h[validation_type][ov].to_s == opts[ov].to_s)
198
- conf_msg << "#{ov}: '#{opts[ov]}'"
199
- unless expected
200
- err_msg << "#{ov}: '#{h[validation_type][ov]}'"
201
- end
443
+ conf_msg << "#{ov}: '#{opts[ov]}'"
444
+ err_msg << "#{ov}: '#{h[validation_type][ov]}'" unless expected
202
445
  matching &&= expected
203
446
  end
204
- end
205
447
 
206
- msg = msg << " with: { #{conf_msg.join(', ')} }" unless conf_msg.empty?
207
- msg << " but found: { #{err_msg.join(', ')} }" unless err_msg.empty?
208
- assert(matching, msg)
448
+ msg <<= " with: { #{conf_msg.join(', ')} }" unless conf_msg.empty?
449
+ msg << " but found: { #{err_msg.join(', ')} }" unless err_msg.empty?
450
+ assert(matching, msg)
209
451
 
452
+ else
453
+ msg << ", but no :#{validation_type} validation is defined for :#{attribute}"
454
+ assert(false, msg)
455
+ end
210
456
  else
211
- msg << ", but no :#{validation_type} validation is defined for :#{attribute}"
457
+ msg << ", but no validations are defined for :#{attribute}"
212
458
  assert(false, msg)
213
459
  end
214
460
  else
215
- msg << ", but no validations are defined for :#{attribute}"
216
- assert(false, msg)
461
+ assert(false, "No validations defined in #{obj.class}")
217
462
  end
218
- else
219
- assert(false, "No validations defined in #{obj.class}")
220
463
  end
221
- end
464
+ # rubocop:enable Metrics/*
222
465
 
466
+ # Test for refuting the presence validation of a model attribute
467
+ #
468
+ # This method checks if the specified attribute of the given object
469
+ # does not have a presence validation. It can be used in both assertion
470
+ # and expectation styles.
471
+ #
472
+ # @param obj [Object] The model object to test
473
+ # @param attribute [Symbol] The attribute to check for absence of presence validation
474
+ # @param opts [Hash] Additional options for the validation (default: {})
475
+ # @param msg [String] Custom error message (default: nil)
476
+ #
477
+ # @example Using assertion style
478
+ # refute_validates_presence(model, :title)
479
+ #
480
+ # @example Using expectation style
481
+ # model.wont_validate_presence_of(:title)
482
+ #
483
+ # @example With custom error message
484
+ # refute_validates_presence(model, :title, {}, "Title should not have presence validation")
485
+ #
486
+ def refute_validates_presence(obj, attribute, opts = {}, msg = nil)
487
+ refute_validates(obj, :presence, attribute, opts, msg)
488
+ end
489
+ alias refute_validates_presence_of refute_validates_presence
223
490
 
224
- # Test for validating presence of a model attribute
225
- #
226
- # it { refute_validates_presence(model, :title) }
227
- # it { model.must_validate_presence_of(:title, { message: '...' }) }
228
- #
229
- def refute_validates_presence(obj, attribute, opts = {}, msg = nil)
230
- refute_validates(obj, :presence, attribute, opts, msg)
231
- end
232
- alias_method :refute_validates_presence_of, :refute_validates_presence
233
-
234
- # Test for validating the length of a model's attribute.
235
- #
236
- # Available options:
237
- #
238
- # :message :: The message to use (no default, overrides :nil_message, :too_long,
239
- # :too_short, and :wrong_length options if present)
240
- #
241
- # :nil_message :: The message to use use if :maximum option is used and the value is nil
242
- # (default: 'is not present')
243
- #
244
- # :too_long :: The message to use use if it the value is too long (default: 'is too long')
245
- #
246
- # :too_short :: The message to use use if it the value is too short
247
- # (default: 'is too short')
248
- #
249
- # :wrong_length :: The message to use use if it the value is not valid
250
- # (default: 'is the wrong length')
251
- #
252
- # SIZE RELATED OPTIONS:
253
- #
254
- # :is :: The exact size required for the value to be valid (no default)
255
- # :minimum :: The minimum size allowed for the value (no default)
256
- # :maximum :: The maximum size allowed for the value (no default)
257
- # :within :: The array/range that must include the size of the value for it to be valid
258
- # (no default)
259
- #
260
- # it { refute_validates_length(model, :title, { maximum: 12 }) }
261
- # it { model.must_validate_length_of(:title, { within: 4..12 }) }
262
- #
263
- def refute_validates_length(obj, attribute, opts = {}, msg = nil)
264
- refute_validates(obj, :length, attribute, opts, msg)
265
- end
266
- alias_method :refute_validates_length_of, :refute_validates_length
267
-
268
- # Test for validating the exact length of a model's attribute.
269
- #
270
- # it { refute_validates_exact_length(model, :title, 12, { message: '...' }) }
271
- # it { model.must_validate_exact_length_of(:title, 12, { message: '...' }) }
272
- #
273
- def refute_validates_exact_length(obj, attribute, exact_length, opts = {}, msg = nil)
274
- opts.merge!(is: exact_length)
275
- refute_validates(obj, :length, attribute, opts, msg)
276
- end
277
- alias_method :refute_validates_exact_length_of, :refute_validates_exact_length
278
-
279
- # Test for validating the exact length of a model's attribute.
280
- #
281
- # it { refute_validates_length_range(model, :title, 4..12, { message: '...' }) }
282
- # it { model.must_validate_length_range_of(:title, 4..12, { message: '...' }) }
283
- #
284
- def refute_validates_length_range(obj, attribute, range, opts = {}, msg = nil)
285
- opts.merge!(within: range)
286
- refute_validates(obj, :length, attribute, opts, msg)
287
- end
288
- alias_method :refute_validates_length_range_of, :refute_validates_length_range
289
-
290
- # Test for validating the maximum length of a model's attribute.
291
- #
292
- # it { refute_validates_max_length(model, :title, 12, { message: '...' }) }
293
- # it { model.must_validate_max_length_of(:title, 12, { message: '...' }) }
294
- #
295
- def refute_validates_max_length(obj, attribute, max_length, opts = {}, msg = nil)
296
- opts.merge!(maximum: max_length)
297
- refute_validates(obj, :length, attribute, opts, msg)
298
- end
299
- alias_method :refute_validates_max_length_of, :refute_validates_max_length
300
-
301
- # Test for validating the minimum length of a model's attribute.
302
- #
303
- # it { refute_validates_min_length(model, :title, 12, { message: '...' }) }
304
- # it { model.must_validate_min_length_of(:title, 12, { message: '...' }) }
305
- #
306
- def refute_validates_min_length(obj, attribute, min_length, opts = {}, msg = nil)
307
- opts.merge!(minimum: min_length)
308
- refute_validates(obj, :length, attribute, opts, msg)
309
- end
310
- alias_method :refute_validates_min_length_of, :refute_validates_min_length
311
-
312
- # Test for validating the format of a model's attribute with a regexp.
313
- #
314
- # it { refute_validates_format(model, :title, 12, { with: /[a-z+]/ }) }
315
- # it { model.must_validate_format_of(:title, 12, { with: /[a-z]+/ }) }
316
- #
317
- def refute_validates_format(obj, attribute, opts = {}, msg = nil)
318
- refute_validates(obj, :format, attribute, opts, msg)
319
- end
320
- alias_method :refute_validates_format_of, :refute_validates_format
321
-
322
- # Test for validating that a model's attribute is within a specified range or set of values.
323
- #
324
- # it { refute_validates_inclusion(model, :status, { in: [:a, :b, :c] }) }
325
- # it { model.must_validate_inclusion_of(:status, { in: [:a, :b, :c] }) }
326
- #
327
- def refute_validates_inclusion(obj, attribute, opts = {}, msg = nil)
328
- refute_validates(obj, :inclusion, attribute, opts, msg)
329
- end
330
- alias_method :refute_validates_inclusion_of, :refute_validates_inclusion
331
-
332
- # Test for validating that a a model's attribute is an integer.
333
- #
334
- # it { refute_validates_integer(model, :author_id, { message: '...' }) }
335
- # it { model.must_validate_integer_of(:author_id, { message: '...' }) }
336
- #
337
- def refute_validates_integer(obj, attribute, opts = {}, msg = nil)
338
- opts.merge!(only_integer: true)
339
- refute_validates(obj, :numericality, attribute, opts, msg)
340
- end
491
+ # Test for refuting the length validation of a model's attribute.
492
+ #
493
+ # This method checks if the specified attribute of the given object
494
+ # does not have a length validation with the provided options. It can be used
495
+ # in both assertion and expectation styles.
496
+ #
497
+ # @param obj [Object] The model object to test
498
+ # @param attribute [Symbol] The attribute to check for absence of length validation
499
+ # @param opts [Hash] Additional options for the validation (default: {})
500
+ # @param msg [String] Custom error message (default: nil)
501
+ #
502
+ # Available options:
503
+ #
504
+ # :message :: The message to use (no default, overrides :nil_message, :too_long,
505
+ # :too_short, and :wrong_length options if present)
506
+ # :nil_message :: The message to use if :maximum option is used and the value is nil
507
+ # (default: 'is not present')
508
+ # :too_long :: The message to use if the value is too long (default: 'is too long')
509
+ # :too_short :: The message to use if the value is too short (default: 'is too short')
510
+ # :wrong_length :: The message to use if the value is not valid
511
+ # (default: 'is the wrong length')
512
+ #
513
+ # Size related options:
514
+ #
515
+ # :is :: The exact size required for the value to be valid (no default)
516
+ # :minimum :: The minimum size allowed for the value (no default)
517
+ # :maximum :: The maximum size allowed for the value (no default)
518
+ # :within :: The array/range that must include the size of the value for it to be valid
519
+ # (no default)
520
+ #
521
+ # @example Using assertion style
522
+ # refute_validates_length(model, :title, { maximum: 12 })
523
+ #
524
+ # @example Using expectation style
525
+ # model.wont_validate_length_of(:title, { within: 4..12 })
526
+ #
527
+ # @example With custom error message
528
+ # refute_validates_length(
529
+ # model,
530
+ # :title,
531
+ # { maximum: 12 },
532
+ # "Title should not have length validation"
533
+ # )
534
+ #
535
+ def refute_validates_length(obj, attribute, opts = {}, msg = nil)
536
+ refute_validates(obj, :length, attribute, opts, msg)
537
+ end
538
+ alias refute_validates_length_of refute_validates_length
341
539
 
342
- # Test for validating that a model's attribute is numeric (number).
343
- #
344
- # it { refute_validates_numericality(model, :author_id, { message: '...' }) }
345
- # it { model.must_validate_numericality_of(:author_id, { message: '...' }) }
346
- #
347
- def refute_validates_numericality(obj, attribute, opts = {}, msg = nil)
348
- refute_validates(obj, :numericality, attribute, opts, msg)
349
- end
350
- alias_method :refute_validates_numericality_of, :refute_validates_numericality
351
-
352
- # Test for validating that a model's attribute is unique.
353
- #
354
- # it { refute_validates_uniqueness(model, :urlslug, { message: '...' }) }
355
- # it { model.must_validate_uniqueness_of(:urlslug, { message: '...' }) }
356
- #
357
- def refute_validates_uniqueness(obj, attribute, opts = {}, msg = nil)
358
- refute_validates(obj, :uniqueness, attribute, opts, msg)
359
- end
360
- alias_method :refute_validates_uniqueness_of, :refute_validates_uniqueness
540
+ # Test for refuting the validation of exact length for a model's attribute.
541
+ #
542
+ # This method checks if the specified attribute of the given object
543
+ # does not have a length validation for an exact length. It can be used in both
544
+ # assertion and expectation styles.
545
+ #
546
+ # @param obj [Object] The model object to test
547
+ # @param attribute [Symbol] The attribute to check for absence of exact length validation
548
+ # @param exact_length [Integer] The exact length to validate against
549
+ # @param opts [Hash] Additional options for the validation (default: {})
550
+ # @param msg [String] Custom error message (default: nil)
551
+ #
552
+ # @example Using assertion style
553
+ # refute_validates_exact_length(
554
+ # model,
555
+ # :title,
556
+ # 12,
557
+ # { message: 'Must not be exactly 12 characters' }
558
+ # )
559
+ #
560
+ # @example Using expectation style
561
+ # model.wont_validate_exact_length_of(
562
+ # :title,
563
+ # 12,
564
+ # { message: 'Must not be exactly 12 characters' }
565
+ # )
566
+ #
567
+ def refute_validates_exact_length(obj, attribute, exact_length, opts = {}, msg = nil)
568
+ # opts.merge!(is: exact_length)
569
+ opts[:is] = exact_length
570
+ refute_validates(obj, :length, attribute, opts, msg)
571
+ end
572
+ alias refute_validates_exact_length_of refute_validates_exact_length
361
573
 
362
- # Validates acceptance of an attribute. Just checks that the value is equal to the :accept option. This method is unique in that :allow_nil is assumed to be true instead of false.
574
+ # Test for refuting the validation of length range for a model's attribute.
575
+ #
576
+ # This method checks if the specified attribute of the given object
577
+ # does not have a length validation within a specified range. It can be used in both
578
+ # assertion and expectation styles.
579
+ #
580
+ # @param obj [Object] The model object to test
581
+ # @param attribute [Symbol] The attribute to check for absence of length range validation
582
+ # @param range [Range] The range of lengths to validate against
583
+ # @param opts [Hash] Additional options for the validation (default: {})
584
+ # @param msg [String] Custom error message (default: nil)
585
+ #
586
+ # @example Using assertion style
587
+ # refute_validates_length_range(
588
+ # model,
589
+ # :title,
590
+ # 4..12,
591
+ # { message: 'Title length must not be between 4 and 12 characters' }
592
+ # )
593
+ #
594
+ # @example Using expectation style
595
+ # model.wont_validate_length_range_of(
596
+ # :title,
597
+ # 4..12,
598
+ # { message: 'Title length must not be between 4 and 12 characters' }
599
+ # )
600
+ #
601
+ def refute_validates_length_range(obj, attribute, range, opts = {}, msg = nil)
602
+ opts[:within] = range
603
+ refute_validates(obj, :length, attribute, opts, msg)
604
+ end
605
+ alias refute_validates_length_range_of refute_validates_length_range
363
606
 
364
- # Test for validating the acceptance of a model's attribute.
365
- #
366
- # it { refute_validates_acceptance(Order.new, :toc, { message: '...' }) }
367
- # it { model.must_validate_acceptance_of(:toc, { message: '...' }) }
368
- #
369
- def refute_validates_acceptance(obj, attribute, opts = {}, msg = nil)
370
- refute_validates(obj, :acceptance, attribute, opts, msg)
371
- end
372
- alias_method :refute_validates_acceptance_of, :refute_validates_acceptance
373
-
374
- # Test for validating the confirmation of a model's attribute.
375
- #
376
- # it { refute_validates_confirmation(User.new, :password, { message: '...' }) }
377
- # it { User.new.must_validate_confirmation_of(:password, { message: '...' }) }
378
- #
379
- def refute_validates_confirmation(obj, attribute, opts = {}, msg = nil)
380
- refute_validates(obj, :confirmation, attribute, opts, msg)
381
- end
382
- alias_method :refute_validates_confirmation_of, :refute_validates_confirmation
383
-
384
- # Base test for validations of a model, used mainly as a shortcut for other assertions
385
- def refute_validates(obj, validation_type, attribute, opts = {}, msg = nil)
386
- msg = msg.nil? ? "" : "#{msg}\n"
387
- unless obj.respond_to?(attribute)
388
- assert(false, "Column :#{attribute} is not defined in #{obj.class}, so cannot be validated")
389
- end
390
- msg << "Expected #{obj.class} NOT to validate :#{attribute} with :#{validation_type}"
391
- if _validated_model?(obj)
392
- if _validated_column?(obj, attribute)
393
- msg << ", but the column :#{attribute} was validated with :#{validation_type}"
394
- assert(false, msg)
607
+ # Test for refuting the maximum length validation of a model's attribute.
608
+ #
609
+ # This method checks if the specified attribute of the given object
610
+ # does not have a length validation with a maximum value. It can be used in both
611
+ # assertion and expectation styles.
612
+ #
613
+ # @param obj [Object] The model object to test
614
+ # @param attribute [Symbol] The attribute to check for absence of maximum length validation
615
+ # @param max_length [Integer] The maximum length to validate against
616
+ # @param opts [Hash] Additional options for the validation (default: {})
617
+ # @param msg [String] Custom error message (default: nil)
618
+ #
619
+ # @example Using assertion style
620
+ # refute_validates_max_length(
621
+ # model,
622
+ # :title,
623
+ # 12,
624
+ # { message: 'Title should not have maximum length validation' }
625
+ # )
626
+ #
627
+ # @example Using expectation style
628
+ # model.wont_validate_max_length_of(
629
+ # :title,
630
+ # 12,
631
+ # { message: 'Title should not have maximum length validation' }
632
+ # )
633
+ #
634
+ def refute_validates_max_length(obj, attribute, max_length, opts = {}, msg = nil)
635
+ opts[:maximum] = max_length
636
+ refute_validates(obj, :length, attribute, opts, msg)
637
+ end
638
+ alias refute_validates_max_length_of refute_validates_max_length
639
+
640
+ # Test for refuting the minimum length validation of a model's attribute.
641
+ #
642
+ # This method checks if the specified attribute of the given object
643
+ # does not have a length validation with a minimum value. It can be used in both
644
+ # assertion and expectation styles.
645
+ #
646
+ # @param obj [Object] The model object to test
647
+ # @param attribute [Symbol] The attribute to check for absence of minimum length validation
648
+ # @param min_length [Integer] The minimum length to validate against
649
+ # @param opts [Hash] Additional options for the validation (default: {})
650
+ # @param msg [String] Custom error message (default: nil)
651
+ #
652
+ # @example Using assertion style
653
+ # refute_validates_min_length(
654
+ # model,
655
+ # :title,
656
+ # 12,
657
+ # { message: 'Title should not have minimum length validation' }
658
+ # )
659
+ #
660
+ # @example Using expectation style
661
+ # model.wont_validate_min_length_of(
662
+ # :title,
663
+ # 12,
664
+ # { message: 'Title should not have minimum length validation' }
665
+ # )
666
+ #
667
+ def refute_validates_min_length(obj, attribute, min_length, opts = {}, msg = nil)
668
+ opts[:minimum] = min_length
669
+ refute_validates(obj, :length, attribute, opts, msg)
670
+ end
671
+ alias refute_validates_min_length_of refute_validates_min_length
672
+
673
+ # Test for refuting the format validation of a model's attribute with a regexp.
674
+ #
675
+ # This method checks if the specified attribute of the given object
676
+ # does not have a format validation with the provided regular expression. It can be used
677
+ # in both assertion and expectation styles.
678
+ #
679
+ # @param obj [Object] The model object to test
680
+ # @param attribute [Symbol] The attribute to check for absence of format validation
681
+ # @param opts [Hash] Additional options for the validation (default: {})
682
+ # @param msg [String] Custom error message (default: nil)
683
+ #
684
+ # @option opts [Regexp] :with The regular expression to validate against (required)
685
+ #
686
+ # @example Using assertion style
687
+ # refute_validates_format(model, :title, { with: /[a-z]+/ })
688
+ #
689
+ # @example Using expectation style
690
+ # model.wont_validate_format_of(:title, { with: /[a-z]+/ })
691
+ #
692
+ # @example With custom error message
693
+ # refute_validates_format(
694
+ # model,
695
+ # :title,
696
+ # { with: /[a-z]+/ },
697
+ # "Title should not have format validation"
698
+ # )
699
+ #
700
+ def refute_validates_format(obj, attribute, opts = {}, msg = nil)
701
+ refute_validates(obj, :format, attribute, opts, msg)
702
+ end
703
+ alias refute_validates_format_of refute_validates_format
704
+
705
+ # Test for refuting the inclusion validation of a model's attribute.
706
+ #
707
+ # This method checks if the specified attribute of the given object
708
+ # does not have an inclusion validation with the provided set of values. It can be used
709
+ # in both assertion and expectation styles.
710
+ #
711
+ # @param obj [Object] The model object to test
712
+ # @param attribute [Symbol] The attribute to check for absence of inclusion validation
713
+ # @param opts [Hash] Additional options for the validation (default: {})
714
+ # @param msg [String] Custom error message (default: nil)
715
+ #
716
+ # @option opts [Array, Range] :in The set of valid values (required)
717
+ #
718
+ # @example Using assertion style
719
+ # refute_validates_inclusion(model, :status, { in: [:a, :b, :c] })
720
+ #
721
+ # @example Using expectation style
722
+ # model.wont_validate_inclusion_of(:status, { in: [:a, :b, :c] })
723
+ #
724
+ # @example With custom error message
725
+ # refute_validates_inclusion(
726
+ # model,
727
+ # :status,
728
+ # { in: [:a, :b, :c] },
729
+ # "Status should not be limited to these values"
730
+ # )
731
+ #
732
+ def refute_validates_inclusion(obj, attribute, opts = {}, msg = nil)
733
+ refute_validates(obj, :inclusion, attribute, opts, msg)
734
+ end
735
+ alias refute_validates_inclusion_of refute_validates_inclusion
736
+
737
+ # Test for refuting the validation that a model's attribute is an integer.
738
+ #
739
+ # This method checks if the specified attribute of the given object
740
+ # does not have an integer validation. It can be used in both assertion
741
+ # and expectation styles.
742
+ #
743
+ # @param obj [Object] The model object to test
744
+ # @param attribute [Symbol] The attribute to check for absence of integer validation
745
+ # @param opts [Hash] Additional options for the validation (default: {})
746
+ # @param msg [String] Custom error message (default: nil)
747
+ #
748
+ # @example Using assertion style
749
+ # refute_validates_integer(model, :author_id, { message: 'must not be an integer' })
750
+ #
751
+ # @example Using expectation style
752
+ # model.wont_validate_integer_of(:author_id, { message: 'must not be an integer' })
753
+ #
754
+ def refute_validates_integer(obj, attribute, opts = {}, msg = nil)
755
+ opts[:only_integer] = true
756
+ refute_validates(obj, :numericality, attribute, opts, msg)
757
+ end
758
+
759
+ # Test for refuting the numericality validation of a model's attribute.
760
+ #
761
+ # This method checks if the specified attribute of the given object
762
+ # does not have a numericality validation. It can be used in both assertion
763
+ # and expectation styles.
764
+ #
765
+ # @param obj [Object] The model object to test
766
+ # @param attribute [Symbol] The attribute to check for absence of numericality validation
767
+ # @param opts [Hash] Additional options for the validation (default: {})
768
+ # @param msg [String] Custom error message (default: nil)
769
+ #
770
+ # @example Using assertion style
771
+ # refute_validates_numericality(model, :price, { greater_than: 0 })
772
+ #
773
+ # @example Using expectation style
774
+ # model.wont_validate_numericality_of(:price, { less_than_or_equal_to: 1000 })
775
+ #
776
+ # @example With custom error message
777
+ # refute_validates_numericality(
778
+ # model,
779
+ # :quantity,
780
+ # { only_integer: true, message: 'must not be a number' }
781
+ # )
782
+ #
783
+ def refute_validates_numericality(obj, attribute, opts = {}, msg = nil)
784
+ refute_validates(obj, :numericality, attribute, opts, msg)
785
+ end
786
+ alias refute_validates_numericality_of refute_validates_numericality
787
+
788
+ # Test for refuting the uniqueness validation of a model's attribute.
789
+ #
790
+ # This method checks if the specified attribute of the given object
791
+ # does not have a uniqueness validation. It can be used in both assertion
792
+ # and expectation styles.
793
+ #
794
+ # @param obj [Object] The model object to test
795
+ # @param attribute [Symbol] The attribute to check for absence of uniqueness validation
796
+ # @param opts [Hash] Additional options for the validation (default: {})
797
+ # @param msg [String] Custom error message (default: nil)
798
+ #
799
+ # @example Using assertion style
800
+ # refute_validates_uniqueness(model, :urlslug, { message: 'should not be unique' })
801
+ #
802
+ # @example Using expectation style
803
+ # model.wont_validate_uniqueness_of(:urlslug, { case_sensitive: false })
804
+ #
805
+ # @example With custom error message
806
+ # refute_validates_uniqueness(
807
+ # model,
808
+ # :email,
809
+ # { scope: :account_id },
810
+ # "Email should not be unique within an account"
811
+ # )
812
+ #
813
+ def refute_validates_uniqueness(obj, attribute, opts = {}, msg = nil)
814
+ refute_validates(obj, :uniqueness, attribute, opts, msg)
815
+ end
816
+ alias refute_validates_uniqueness_of refute_validates_uniqueness
817
+
818
+ # Test for refuting the acceptance validation of a model's attribute.
819
+ #
820
+ # This method checks if the specified attribute of the given object
821
+ # does not have an acceptance validation. It can be used in both assertion
822
+ # and expectation styles.
823
+ #
824
+ # @param obj [Object] The model object to test
825
+ # @param attribute [Symbol] The attribute to check for absence of acceptance validation
826
+ # @param opts [Hash] Additional options for the validation (default: {})
827
+ # @param msg [String] Custom error message (default: nil)
828
+ #
829
+ # @example Using assertion style
830
+ # refute_validates_acceptance(Order.new, :toc, { message: 'should not require acceptance' })
831
+ #
832
+ # @example Using expectation style
833
+ # model.wont_validate_acceptance_of(:toc, { accept: 'yes' })
834
+ #
835
+ # @note The acceptance validation is typically used for checkboxes in web forms
836
+ # where the user needs to accept terms of service. This method ensures
837
+ # that such validation is not present.
838
+ #
839
+ def refute_validates_acceptance(obj, attribute, opts = {}, msg = nil)
840
+ refute_validates(obj, :acceptance, attribute, opts, msg)
841
+ end
842
+ alias refute_validates_acceptance_of refute_validates_acceptance
843
+
844
+ # Test for refuting the confirmation validation of a model's attribute.
845
+ #
846
+ # This method checks if the specified attribute of the given object
847
+ # does not have a confirmation validation. It can be used in both assertion
848
+ # and expectation styles.
849
+ #
850
+ # @param obj [Object] The model object to test
851
+ # @param attribute [Symbol] The attribute to check for absence of confirmation validation
852
+ # @param opts [Hash] Additional options for the validation (default: {})
853
+ # @param msg [String] Custom error message (default: nil)
854
+ #
855
+ # @example Using assertion style
856
+ # refute_validates_confirmation(
857
+ # User.new,
858
+ # :password,
859
+ # { message: 'should not require confirmation' }
860
+ # )
861
+ #
862
+ # @example Using expectation style
863
+ # User.new.wont_validate_confirmation_of(
864
+ # :password,
865
+ # { message: 'should not require confirmation' }
866
+ # )
867
+ #
868
+ # @note The confirmation validation is typically used for password fields
869
+ # where the user needs to enter the same password twice. This method
870
+ # ensures that such validation is not present.
871
+ #
872
+ def refute_validates_confirmation(obj, attribute, opts = {}, msg = nil)
873
+ refute_validates(obj, :confirmation, attribute, opts, msg)
874
+ end
875
+ alias refute_validates_confirmation_of refute_validates_confirmation
876
+
877
+ # Base test for refuting validations of a model
878
+ #
879
+ # This method checks if the specified attribute of the given object
880
+ # does not have the specified validation type. It is used as a foundation
881
+ # for other refutation assertions.
882
+ #
883
+ # @param obj [Object] The model object to test
884
+ # @param validation_type [Symbol] The type of validation to check for absence
885
+ # @param attribute [Symbol] The attribute to check for absence of validation
886
+ # @param _opts [Hash] Additional options for the validation (unused in this method)
887
+ # @param msg [String] Custom error message (default: nil)
888
+ #
889
+ # @example Refuting presence validation
890
+ # refute_validates(User.new, :presence, :name)
891
+ #
892
+ # @example Refuting length validation with custom message
893
+ # refute_validates(Post.new, :length, :title, {}, "Title should not have length validation")
894
+ #
895
+ # @raise [Minitest::Assertion] If the validation exists when it should not
896
+ #
897
+ # rubocop:disable Metrics/MethodLength
898
+ def refute_validates(obj, validation_type, attribute, _opts = {}, msg = nil)
899
+ msg = msg.nil? ? '' : "#{msg}\n"
900
+
901
+ unless obj.respond_to?(attribute)
902
+ assert(false, "Column :#{attribute} is not defined in #{obj.class}, so cannot be validated")
903
+ end
904
+
905
+ msg << "Expected #{obj.class} NOT to validate :#{attribute} with :#{validation_type}"
906
+ if _validated_model?(obj)
907
+ if _validated_column?(obj, attribute)
908
+ msg << ", but the column :#{attribute} was validated with :#{validation_type}"
909
+ assert(false, msg)
910
+ else
911
+ assert(true, msg)
912
+ end
395
913
  else
396
- assert(true, msg)
914
+ assert(false, "No validations defined in #{obj.class}")
397
915
  end
398
- else
399
- assert(false, "No validations defined in #{obj.class}")
400
916
  end
401
- end
917
+ # rubocop:enable Metrics/MethodLength
402
918
 
403
- #
404
- def assert_raises_validation_failed(obj)
405
- assert_raises(::Sequel::ValidationFailed) { obj.save }
406
- end
407
- alias_method :assert_fails_validation, :assert_raises_validation_failed
408
-
409
- # #
410
- # #
411
- # def assert_presence(obj, attr, value)
412
- # obj.send("#{attr}=", value)
413
- # assert(obj.valid?)
414
- # end
415
- #
416
- # [nil, '', ' '].each { |x| }
417
- #
418
- # end
419
-
420
- private
421
-
422
- #
423
- def _validated_model?(model)
424
- (model.class.respond_to?(:has_validations?) && model.class.has_validations?)
425
- end
919
+ # Test that saving an object raises a ValidationFailed error
920
+ #
921
+ # This method attempts to save the given object and asserts that it raises
922
+ # a Sequel::ValidationFailed error. It can be used to test that invalid objects
923
+ # fail validation when attempting to save.
924
+ #
925
+ # @param obj [Object] The model object to test
926
+ #
927
+ # @example Using assertion style
928
+ # assert_raises_validation_failed(invalid_user)
929
+ #
930
+ # @example Using expectation style
931
+ # invalid_user.must_fail_validation
932
+ #
933
+ # @raise [Minitest::Assertion] If saving the object does not raise Sequel::ValidationFailed
934
+ #
935
+ def assert_raises_validation_failed(obj)
936
+ assert_raises(::Sequel::ValidationFailed) { obj.save }
937
+ end
938
+ alias assert_fails_validation assert_raises_validation_failed
426
939
 
427
- #
428
- def _validated_column?(model, attribute)
429
- return false unless _validated_model?(model)
430
- model.class.validation_reflections.keys.include?(attribute.to_sym)
431
- end
940
+ private
432
941
 
433
- #
434
- def _validated_with_validation_type?(model, attribute, validation_type)
435
- return false unless _validated_column?(model, attribute)
436
- _validation_types_hash_for_column(model, attribute).keys.include?(validation_type)
437
- end
942
+ # Check if the model has validations
943
+ #
944
+ # This method determines whether the given model class has any validations defined.
945
+ #
946
+ # @param model [Object] The model object to check for validations
947
+ # @return [Boolean] True if the model has validations, false otherwise
948
+ #
949
+ # @example
950
+ # _validated_model?(User.new) #=> true
951
+ # _validated_model?(UnvalidatedModel.new) #=> false
952
+ #
953
+ def _validated_model?(model)
954
+ model.class.respond_to?(:has_validations?) && model.class.has_validations?
955
+ end
438
956
 
439
- #
440
- def _validation_types_hash_for_column(model, attribute)
441
- h = {}
442
- model.class.validation_reflections[attribute].each { |c| h[c[0]] = c[1] }
443
- h
444
- end
957
+ # Check if a specific attribute of the model has validations
958
+ #
959
+ # This method determines whether the given attribute of the model has any validations defined.
960
+ #
961
+ # @param model [Object] The model object to check for validations
962
+ # @param attribute [Symbol, String] The attribute to check for validations
963
+ # @return [Boolean] True if the attribute has validations, false otherwise
964
+ #
965
+ # @example
966
+ # _validated_column?(User.new, :email) #=> true
967
+ # _validated_column?(User.new, :unvalidated_field) #=> false
968
+ #
969
+ def _validated_column?(model, attribute)
970
+ return false unless _validated_model?(model)
445
971
 
446
- #
447
- def _available_validation_types
448
- [:format, :length, :presence, :numericality, :confirmation, :acceptance, :inclusion, :uniqueness]
449
- end
972
+ model.class.validation_reflections.key?(attribute.to_sym)
973
+ end
450
974
 
451
- #
452
- def _available_validation_options
453
- [
454
- :message, :if, :is, :in, :allow_blank, :allow_missing, :allow_nil, :accept, :with, :within,
455
- :only_integer, :maximum, :minimum, :nil_message, :too_long, :too_short, :wrong_length
456
- ]
457
- end
975
+ # Check if a specific attribute of the model has a specific validation type
976
+ #
977
+ # This method determines whether the given attribute of the model has the specified
978
+ # validation type.
979
+ #
980
+ # @param model [Object] The model object to check for validations
981
+ # @param attribute [Symbol, String] The attribute to check for validations
982
+ # @param validation_type [Symbol] The type of validation to check for
983
+ # @return [Boolean] True if the attribute has the specified validation type, false otherwise
984
+ #
985
+ # @example
986
+ # _validated_with_validation_type?(User.new, :email, :presence) #=> true
987
+ # _validated_with_validation_type?(User.new, :email, :format) #=> true
988
+ # _validated_with_validation_type?(User.new, :email, :length) #=> false
989
+ #
990
+ def _validated_with_validation_type?(model, attribute, validation_type)
991
+ return false unless _validated_column?(model, attribute)
458
992
 
459
- #
460
- def _valid_validation_options(type = nil)
461
- arr = [:message]
462
- case type.to_sym
463
- when :each
464
- # validates_each (*atts, &block)
465
- # Adds a validation for each of the given attributes using the supplied block.
466
- [:allow_blank, :allow_missing, :allow_nil].each { |a| arr << a }
467
- when :acceptance
468
- # The value required for the object to be valid (default: '1')
469
- arr << :accept
470
- when :format
471
- # The regular expression to validate the value with (required).
472
- arr << :with
473
- when :inclusion
474
- # An array or range of values to check for validity (required)
475
- arr << :in
476
- when :numericality
477
- # Whether only integers are valid values (default: false)
478
- arr << :only_integer
479
- when :length
480
- #
481
- # :message :: The message to use (no default, overrides :nil_message, :too_long,
482
- # :too_short, and :wrong_length options if present)
483
- #
484
- # :nil_message :: The message to use use if :maximum option is used and the value is nil
485
- # (default: 'is not present')
486
- #
487
- # :too_long :: The message to use use if it the value is too long (default: 'is too long')
488
- #
489
- # :too_short :: The message to use use if it the value is too short
490
- # (default: 'is too short')
491
- #
492
- # :wrong_length :: The message to use use if it the value is not valid
493
- # (default: 'is the wrong length')
494
- #
495
- # SIZE
496
- # :is :: The exact size required for the value to be valid (no default)
497
- # :minimum :: The minimum size allowed for the value (no default)
498
- # :maximum :: The maximum size allowed for the value (no default)
499
- # :within :: The array/range that must include the size of the value for it to be valid
500
- # (no default)
501
-
502
- [:is, :maximum, :minimum, :nil_message, :too_long, :too_short, :within, :wrong_length].each { |a| arr << a }
503
- else
993
+ _validation_types_hash_for_column(model, attribute).key?(validation_type)
994
+ end
995
+
996
+ # Get a hash of validation types and their options for a specific attribute
997
+ #
998
+ # This method creates a hash where the keys are validation types (e.g., :presence, :format)
999
+ # and the values are the corresponding validation options for the specified attribute.
1000
+ #
1001
+ # @param model [Object] The model object to check for validations
1002
+ # @param attribute [Symbol, String] The attribute to get validations for
1003
+ # @return [Hash] A hash of validation types and their options
1004
+ #
1005
+ # @example
1006
+ # _validation_types_hash_for_column(User.new, :email)
1007
+ # #=> { presence: {}, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i } }
1008
+ #
1009
+ def _validation_types_hash_for_column(model, attribute)
1010
+ h = {}
1011
+ model.class.validation_reflections[attribute].each { |c| h[c[0]] = c[1] }
1012
+ h
1013
+ end
1014
+
1015
+ # Get an array of available validation types
1016
+ #
1017
+ # This method returns an array of symbols representing the available
1018
+ # validation types in Sequel.
1019
+ #
1020
+ # @return [Array<Symbol>] An array of available validation type symbols
1021
+ #
1022
+ # @example
1023
+ # _available_validation_types
1024
+ # #=> [
1025
+ # :format,
1026
+ # :length,
1027
+ # :presence,
1028
+ # :numericality,
1029
+ # :confirmation,
1030
+ # :acceptance,
1031
+ # :inclusion,
1032
+ # :uniqueness
1033
+ # ]
1034
+ #
1035
+ def _available_validation_types
1036
+ %i[format length presence numericality confirmation acceptance inclusion uniqueness]
1037
+ end
1038
+
1039
+ # Get an array of available validation options
1040
+ #
1041
+ # This method returns an array of symbols representing the available
1042
+ # validation options in Sequel. These options can be used across
1043
+ # different validation types.
1044
+ #
1045
+ # @return [Array<Symbol>] An array of available validation option symbols
1046
+ #
1047
+ # @example
1048
+ # _available_validation_options
1049
+ # #=> [
1050
+ # :message, :if, :is, :in, :allow_blank, :allow_missing, :allow_nil, :accept, :with,
1051
+ # :within, :only_integer, :maximum, :minimum, :nil_message, :too_long, :too_short,
1052
+ # :wrong_length
1053
+ # ]
1054
+ #
1055
+ def _available_validation_options
1056
+ %i[
1057
+ message if is in allow_blank allow_missing allow_nil accept with within
1058
+ only_integer maximum minimum nil_message too_long too_short wrong_length
1059
+ ]
1060
+ end
1061
+
1062
+ # Get valid validation options for a specific validation type
1063
+ #
1064
+ # This method returns an array of symbols representing the valid
1065
+ # validation options for a given validation type. If no type is specified,
1066
+ # it returns a base set of options common to all validation types.
1067
+ #
1068
+ # @param type [Symbol, nil] The validation type to get options for (default: nil)
1069
+ # @return [Array<Symbol>] An array of valid validation option symbols
1070
+ #
1071
+ # @example
1072
+ # _valid_validation_options(:length)
1073
+ # #=> [
1074
+ # :message, :is, :maximum, :minimum, :nil_message,
1075
+ # :too_long, :too_short, :within, :wrong_length
1076
+ # ]
1077
+ #
1078
+ # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
1079
+ def _valid_validation_options(type = nil)
1080
+ arr = [:message]
1081
+ unless type.nil?
1082
+ case type.to_sym
1083
+ when :each
1084
+ # validates_each (*atts, &block)
1085
+ # Adds a validation for each of the given attributes using the supplied block.
1086
+ %i[allow_blank allow_missing allow_nil].each { |a| arr << a }
1087
+ when :acceptance
1088
+ # The value required for the object to be valid (default: '1')
1089
+ arr << :accept
1090
+ when :format
1091
+ # The regular expression to validate the value with (required).
1092
+ arr << :with
1093
+ when :inclusion
1094
+ # An array or range of values to check for validity (required)
1095
+ arr << :in
1096
+ when :numericality
1097
+ # Whether only integers are valid values (default: false)
1098
+ arr << :only_integer
1099
+ when :length
1100
+ # :message :: The message to use (no default, overrides :nil_message, :too_long,
1101
+ # :too_short, and :wrong_length options if present)
1102
+ # :nil_message :: The message to use if :maximum option is used and the value is nil
1103
+ # (default: 'is not present')
1104
+ # :too_long :: The message to use if the value is too long (default: 'is too long')
1105
+ # :too_short :: The message to use if the value is too short
1106
+ # (default: 'is too short')
1107
+ # :wrong_length :: The message to use if the value is not valid
1108
+ # (default: 'is the wrong length')
1109
+ # :is :: The exact size required for the value to be valid (no default)
1110
+ # :minimum :: The minimum size allowed for the value (no default)
1111
+ # :maximum :: The maximum size allowed for the value (no default)
1112
+ # :within :: The array/range that must include size of the value for it to be valid
1113
+ # (no default)
1114
+
1115
+ %i[is maximum minimum nil_message too_long too_short within wrong_length].each do |a|
1116
+ arr << a
1117
+ end
1118
+ else
1119
+ arr
1120
+ end
1121
+ end
504
1122
  arr
505
- end unless type.nil?
506
- arr
1123
+ end
1124
+ # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
507
1125
  end
1126
+ # /module Assertions
1127
+ # rubocop:enable Metrics/ModuleLength
508
1128
 
509
- end
1129
+ # add support for Spec syntax
1130
+ module Expectations
1131
+ infect_an_assertion :assert_validates, :must_validate, :reverse
1132
+ infect_an_assertion :assert_validates_presence, :must_validate_presence_of, :reverse
1133
+ infect_an_assertion :assert_validates_format, :must_validate_format_of, :reverse
1134
+
1135
+ infect_an_assertion :assert_validates_length, :must_validate_length_of, :reverse
1136
+ infect_an_assertion :assert_validates_exact_length, :must_validate_exact_length_of, :reverse
1137
+ infect_an_assertion :assert_validates_min_length, :must_validate_min_length_of, :reverse
1138
+ infect_an_assertion :assert_validates_max_length, :must_validate_max_length_of, :reverse
1139
+ infect_an_assertion :assert_validates_length_range, :must_validate_length_range_of, :reverse
1140
+
1141
+ infect_an_assertion :assert_validates_integer, :must_validate_integer_of, :reverse
1142
+ infect_an_assertion :assert_validates_numericality, :must_validate_numericality_of, :reverse
1143
+ infect_an_assertion :assert_validates_confirmation, :must_validate_confirmation_of, :reverse
1144
+ infect_an_assertion :assert_validates_acceptance, :must_validate_acceptance_of, :reverse
1145
+ infect_an_assertion :assert_validates_inclusion, :must_validate_inclusion_of, :reverse
1146
+ infect_an_assertion :assert_validates_uniqueness, :must_validate_uniqueness_of, :reverse
1147
+
1148
+ infect_an_assertion :assert_fails_validation, :must_fail_validation, :reverse
510
1149
 
511
- # add support for Spec syntax
512
- module Minitest::Expectations
513
- infect_an_assertion :assert_validates, :must_validate, :reverse
514
- infect_an_assertion :assert_validates_presence, :must_validate_presence_of, :reverse
515
- infect_an_assertion :assert_validates_format, :must_validate_format_of, :reverse
516
-
517
- infect_an_assertion :assert_validates_length, :must_validate_length_of, :reverse
518
- infect_an_assertion :assert_validates_exact_length, :must_validate_exact_length_of, :reverse
519
- infect_an_assertion :assert_validates_min_length, :must_validate_min_length_of, :reverse
520
- infect_an_assertion :assert_validates_max_length, :must_validate_max_length_of, :reverse
521
- infect_an_assertion :assert_validates_length_range, :must_validate_length_range_of, :reverse
522
-
523
- infect_an_assertion :assert_validates_integer, :must_validate_integer_of, :reverse
524
- infect_an_assertion :assert_validates_numericality, :must_validate_numericality_of, :reverse
525
- infect_an_assertion :assert_validates_confirmation, :must_validate_confirmation_of, :reverse
526
- infect_an_assertion :assert_validates_acceptance, :must_validate_acceptance_of, :reverse
527
- infect_an_assertion :assert_validates_inclusion, :must_validate_inclusion_of, :reverse
528
- infect_an_assertion :assert_validates_uniqueness, :must_validate_uniqueness_of, :reverse
529
-
530
- infect_an_assertion :assert_fails_validation, :must_fail_validation, :reverse
531
-
532
-
533
- infect_an_assertion :refute_validates, :wont_validate, :reverse
534
- infect_an_assertion :refute_validates_presence, :wont_validate_presence_of, :reverse
535
- infect_an_assertion :refute_validates_format, :wont_validate_format_of, :reverse
536
-
537
- infect_an_assertion :refute_validates_length, :wont_validate_length_of, :reverse
538
- infect_an_assertion :refute_validates_exact_length, :wont_validate_exact_length_of, :reverse
539
- infect_an_assertion :refute_validates_min_length, :wont_validate_min_length_of, :reverse
540
- infect_an_assertion :refute_validates_max_length, :wont_validate_max_length_of, :reverse
541
- infect_an_assertion :refute_validates_length_range, :wont_validate_length_range_of, :reverse
542
-
543
- infect_an_assertion :refute_validates_integer, :wont_validate_integer_of, :reverse
544
- infect_an_assertion :refute_validates_numericality, :wont_validate_numericality_of, :reverse
545
- infect_an_assertion :refute_validates_confirmation, :wont_validate_confirmation_of, :reverse
546
- infect_an_assertion :refute_validates_acceptance, :wont_validate_acceptance_of, :reverse
547
- infect_an_assertion :refute_validates_inclusion, :wont_validate_inclusion_of, :reverse
548
- infect_an_assertion :refute_validates_uniqueness, :wont_validate_uniqueness_of, :reverse
1150
+ infect_an_assertion :refute_validates, :wont_validate, :reverse
1151
+ infect_an_assertion :refute_validates_presence, :wont_validate_presence_of, :reverse
1152
+ infect_an_assertion :refute_validates_format, :wont_validate_format_of, :reverse
1153
+
1154
+ infect_an_assertion :refute_validates_length, :wont_validate_length_of, :reverse
1155
+ infect_an_assertion :refute_validates_exact_length, :wont_validate_exact_length_of, :reverse
1156
+ infect_an_assertion :refute_validates_min_length, :wont_validate_min_length_of, :reverse
1157
+ infect_an_assertion :refute_validates_max_length, :wont_validate_max_length_of, :reverse
1158
+ infect_an_assertion :refute_validates_length_range, :wont_validate_length_range_of, :reverse
1159
+
1160
+ infect_an_assertion :refute_validates_integer, :wont_validate_integer_of, :reverse
1161
+ infect_an_assertion :refute_validates_numericality, :wont_validate_numericality_of, :reverse
1162
+ infect_an_assertion :refute_validates_confirmation, :wont_validate_confirmation_of, :reverse
1163
+ infect_an_assertion :refute_validates_acceptance, :wont_validate_acceptance_of, :reverse
1164
+ infect_an_assertion :refute_validates_inclusion, :wont_validate_inclusion_of, :reverse
1165
+ infect_an_assertion :refute_validates_uniqueness, :wont_validate_uniqueness_of, :reverse
1166
+ end
549
1167
  end