szilm-validates_timeliness 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/CHANGELOG +116 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +403 -0
  4. data/Rakefile +52 -0
  5. data/TODO +8 -0
  6. data/lib/validates_timeliness.rb +49 -0
  7. data/lib/validates_timeliness/action_view/instance_tag.rb +52 -0
  8. data/lib/validates_timeliness/active_record/attribute_methods.rb +77 -0
  9. data/lib/validates_timeliness/active_record/multiparameter_attributes.rb +69 -0
  10. data/lib/validates_timeliness/formats.rb +365 -0
  11. data/lib/validates_timeliness/locale/en.yml +18 -0
  12. data/lib/validates_timeliness/matcher.rb +1 -0
  13. data/lib/validates_timeliness/parser.rb +44 -0
  14. data/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb +162 -0
  15. data/lib/validates_timeliness/validation_methods.rb +46 -0
  16. data/lib/validates_timeliness/validator.rb +230 -0
  17. data/lib/validates_timeliness/version.rb +3 -0
  18. data/spec/action_view/instance_tag_spec.rb +194 -0
  19. data/spec/active_record/attribute_methods_spec.rb +157 -0
  20. data/spec/active_record/multiparameter_attributes_spec.rb +118 -0
  21. data/spec/formats_spec.rb +306 -0
  22. data/spec/ginger_scenarios.rb +19 -0
  23. data/spec/parser_spec.rb +61 -0
  24. data/spec/resources/application.rb +2 -0
  25. data/spec/resources/person.rb +3 -0
  26. data/spec/resources/schema.rb +10 -0
  27. data/spec/resources/sqlite_patch.rb +19 -0
  28. data/spec/spec/rails/matchers/validate_timeliness_spec.rb +245 -0
  29. data/spec/spec_helper.rb +58 -0
  30. data/spec/time_travel/MIT-LICENSE +20 -0
  31. data/spec/time_travel/time_extensions.rb +33 -0
  32. data/spec/time_travel/time_travel.rb +12 -0
  33. data/spec/validator_spec.rb +713 -0
  34. metadata +102 -0
@@ -0,0 +1,116 @@
1
+ = 2.3.1 [2010-03-19]
2
+ - Fixed bug where custom attribute writer method for date/times were being overriden
3
+
4
+ = 2.3.0 [2010-02-04]
5
+ - Backwards incompatible change to :equal_to option. Fixed error message clash with :equal_to option which exists in Rails already. Option is now :is_at.
6
+ - Fixed I18n support so it returns missing translation message instead of error
7
+ - Fixed attribute method bug. Write method was bypassed when method was first generated and used Rails default parser.
8
+ - Fixed date/time selects when using enable_datetime_select_extension! when some values empty
9
+ - Fixed ISO8601 datetime format which is now split into two formats
10
+ - Changed I18n error value format to fallback to global default if missing in locale
11
+ - Refactored date/time select invalid value extension to use param values. Functionality will be extracted from plugin for v3.
12
+
13
+ = 2.2.2 [2009-09-19]
14
+ - Fixed dummy_time using make_time to respect timezone. Fixes 1.9.1 bug.
15
+
16
+ = 2.2.1 [2009-09-12]
17
+ - Fixed dummy date part for time types in Validator.type_cast_value
18
+ - No more core extensions! Removed dummy_time methods.
19
+
20
+ = 2.2.0 [2009-09-12]
21
+ - Ruby 1.9 support!
22
+ - Customise dummy date values for time types. See DUMMY DATE FOR TIME TYPES.
23
+ - Fixed matcher conflict with Shoulda. Load plugin matcher manually now see matcher section in README
24
+ - Fixed :ignore_usec when used with :with_time or :with_date
25
+ - Some clean up and refactoring
26
+
27
+ = 2.1.0 [2009-06-20]
28
+ - Added ambiguous year threshold setting in Formats class to customize the threshold for 2 digit years (See README)
29
+ - Fixed interpolation values in custom error message for Rails 2.2+
30
+ - Fixed custom I18n local override of en locale
31
+ - Dramatically simplified ActiveRecord monkey patching and hackery
32
+
33
+ = 2.0.0 [2009-04-12]
34
+ - Error value formats are now specified in the i18n locale file instead of updating plugin hash. See OTHER CUSTOMISATION section in README.
35
+ - Date/time select helper extension is disabled by default. To enable see DISPLAY INVALID VALUES IN DATE HELPERS section in README to enable.
36
+ - Added :format option to limit validation to a single format if desired
37
+ - Matcher now supports :equal_to option
38
+ - Formats.parse can take :include_offset option to include offset value from string in seconds, if string contains an offset. Offset not used in rest of plugin yet.
39
+ - Refactored to remove as much plugin code from ActiveRecord as possible.
40
+
41
+ = 1.1.7 [2009-03-26]
42
+ - Minor change to multiparameter attributes which I had not properly implemented for chaining
43
+
44
+ = 1.1.6 [2009-03-19]
45
+ - Rail 2.3 support
46
+ - Added :with_date and :with_time options. They allow an attribute to be combined with another attribute or value to make a datetime value for validation against the temporal restrictions
47
+ - Added :equal_to option
48
+ - Option key validation
49
+ - Better behaviour with other plugins using alias_method_chain on read_attribute and define_attribute_methods
50
+ - Added option to enable datetime_select extension for future use to optionally enable. Enabled by default until version 2.
51
+ - Added :ignore_usec option for datetime restrictions to be compared without microsecond
52
+ - some refactoring
53
+
54
+ = 1.1.5 [2009-01-21]
55
+ - Fixed regex for 'yy' format token which wasn't greedy enough for date formats ending with year when a datetime string parsed as date with a 4 digit year
56
+
57
+ = 1.1.4 [2009-01-13]
58
+ - Make months names respect i18n in Formats
59
+
60
+ = 1.1.3 [2009-01-13]
61
+ - Fixed bug where time and date attributes still being parsed on read using Rails default parser [reported by Brad (pvjq)]
62
+
63
+ = 1.1.2 [2009-01-12]
64
+ - Fixed bugs
65
+ - matcher failing for custom error message without interpolation keys using I18n
66
+ - validator custom error messages not being extracted
67
+
68
+ = 1.1.1 [2009-01-03]
69
+ - Fixed bug in matcher for options local variable
70
+
71
+ = 1.1.0 [2009-01-01]
72
+ - Added between option
73
+
74
+ = 1.0.0 [2008-12-06]
75
+ - Gemified!
76
+ - Refactor of plugin into a Data Mapper style validator class which makes for a cleaner implementation and possible future Merb\Data Mapper support
77
+ - Added Rails 2.2 i18n support. Plugin error messages can specified in locale files. See README.
78
+ - ignore_datetime_restriction_errors setting has been moved from AR to ValidatesTimeliness::Validator.ignore_restriction_errors
79
+ - date_time_error_value_formats setting has been moved from AR to ValidatesTimeliness::Validator.error_value_formats
80
+ - Namespaced modules and specs
81
+ - Clean up of specs
82
+ - fixed a few bugs
83
+ - accessor methods not generating properly due method name stored as symbol in generated_attributes which fails on lookup
84
+ - force value assigned to time/datetime attributes to time objects
85
+
86
+ = 0.1.0 [2008-12-06]
87
+ - Tagged plugin as version 0.1.0
88
+
89
+ = 2008-11-13
90
+ - allow uppercase meridian to be valid [reported by Alex (http://alex.digns.com/)]
91
+
92
+ = 2008-10-28
93
+ - fixed bug when dirty attributes not reflecting change when attribute changed from time value to nil [reported by Brad (pvjq)]
94
+ - fixes for Rails 2.2 compatibility. Will refactor in to Rails version specific branches in the future.
95
+
96
+ = 2008-09-24
97
+ - refactored attribute write method definitions
98
+
99
+ = 2008-08-25
100
+ - fixed bug for non-timezone write method not updating changed attributes hash [reported by Sylvestre Mergulhão]
101
+
102
+ = 2008-08-22
103
+ - fixed bug with attribute cache not clearing on write for date and time columns [reported by Sylvestre Mergulhão]
104
+ - parse method returns Date object for date column assigned string as per normal Rails behaviour
105
+ - parse method returns same object type when assigned Date or Time object as per normal Rails behaviour
106
+
107
+ = 2008-08-07
108
+ - modified matcher option value parsing to allow same value types as validation method
109
+ - fixed matcher message
110
+
111
+ = 2008-08-02
112
+ - refactored validation
113
+ - refactored matcher
114
+
115
+ = 2008-07-30
116
+ - removed setting values to nil when validation fails to preserve before_type_cast value
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Adam Meehan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,403 @@
1
+ = validates_timeliness
2
+
3
+ * Source: http://github.com/adzap/validates_timeliness
4
+ * Bugs: http://github.com/adzap/validates_timeliness/issues
5
+
6
+ == DESCRIPTION:
7
+
8
+ Validate dates, times and datetimes for Rails 2.x. Plays nicely with Rails
9
+ automatic timezone handling. Allows you to add custom formats or remove defaults
10
+ easily. This allows you to control what you think should be a valid date or
11
+ time string.
12
+
13
+
14
+ == FEATURES:
15
+
16
+ * Adds ActiveRecord validation for dates, times and datetimes
17
+
18
+ * Add or remove date/time formats to customize validation
19
+
20
+ * Create new formats using very simple date/time format tokens
21
+
22
+ * Restores ability to see raw value entered for date/time attributes with
23
+ _before_type_cast modifier, which was lost in Rails 2.1.
24
+
25
+ * Supports Rails timezone handling
26
+
27
+ * Supports Rails I18n for the error messages
28
+
29
+ * Rspec matcher for testing model validation of dates and times
30
+
31
+
32
+ == INSTALLATION:
33
+
34
+ As plugin (from master)
35
+
36
+ ./script/plugin install git://github.com/adzap/validates_timeliness.git
37
+
38
+ As gem
39
+
40
+ sudo gem install validates_timeliness
41
+
42
+ # in environment.rb
43
+
44
+ config.gem 'validates_timeliness'
45
+
46
+
47
+ == USAGE:
48
+
49
+ To validate a model with a date, time or datetime attribute you just use the
50
+ validation method
51
+
52
+ class Person < ActiveRecord::Base
53
+ validates_date :date_of_birth
54
+
55
+ end
56
+
57
+ The list of validation methods available are as follows:
58
+ validates_date - validate value as date
59
+ validates_time - validate value as time only i.e. '12:20pm'
60
+ validates_datetime - validate value as a full date and time
61
+
62
+ The validation methods take the usual options plus some specific ones to restrict
63
+ the valid range of dates or times allowed
64
+
65
+ Temporal options (or restrictions):
66
+ :is_at - Attribute must be equal to value to be valid
67
+ :before - Attribute must be before this value to be valid
68
+ :on_or_before - Attribute must be equal to or before this value to be valid
69
+ :after - Attribute must be after this value to be valid
70
+ :on_or_after - Attribute must be equal to or after this value to be valid
71
+ :between - Attribute must be between the values to be valid. Takes an array of two values or a range
72
+
73
+ Regular validation options:
74
+ :allow_nil - Allow a nil value to be valid
75
+ :allow_blank - Allows a nil or empty string value to be valid
76
+ :if - Execute validation when :if evaluates true
77
+ :unless - Execute validation when :unless evaluates false
78
+
79
+ Special options:
80
+ :with_time - Validate a date attribute value combined with a time value against any temporal restrictions
81
+ :with_date - Validate a time attribute value combined with a date value against any temporal restrictions
82
+ :ignore_usec - Ignores microsecond value on datetime restrictions
83
+ :format - Limit validation to a single format for special cases. Takes plugin format value.
84
+
85
+ Message options: - Use these to override the default error messages
86
+ :invalid_date_message
87
+ :invalid_time_message
88
+ :invalid_datetime_message
89
+ :is_at_message
90
+ :before_message
91
+ :on_or_before_message
92
+ :after_message
93
+ :on_or_after_message
94
+ :between_message
95
+
96
+ The temporal restrictions, with_date and with_time can take 4 different value types:
97
+ * String value
98
+ * Date, Time, or DateTime object value
99
+ * Proc or lambda object which may take an optional parameter being the record object
100
+ * A symbol matching the method name in the model
101
+
102
+ When an attribute value is compared to temporal restrictions, they are compared as
103
+ the same type as the validation method type. So using validates_date means all
104
+ values are compared as dates. This is except in the case of with_time and with_date
105
+ options which effectively force the value to validated as a datetime against the
106
+ temporal options.
107
+
108
+ == EXAMPLES:
109
+
110
+ validates_date :date_of_birth :before => lambda { 18.years.ago },
111
+ :before_message => "must be at least 18 years old"
112
+
113
+ validates_time :breakfast_time, :on_or_after => '6:00am',
114
+ :on_or_after_message => 'must be after opening time',
115
+ :before => :second_breakfast_time,
116
+ :allow_nil => true
117
+
118
+ validates_datetime :appointment_date, :before => lambda { 1.week.from_now }
119
+
120
+ validates_date :entry_date, :with_time => '17:00', :on_or_before => :competition_closing
121
+
122
+
123
+ === DATE/TIME FORMATS:
124
+
125
+ So what formats does the plugin allow. Well there are default formats which can
126
+ be added to easily using the plugins format rules. Also formats can be easily
127
+ removed without hacking the plugin at all.
128
+
129
+ Below are the default formats. If you think they are easy to read then you will
130
+ be happy to know that is exactly the format you can use to define your own if
131
+ you want. No complex regular expressions or duck punching (monkey patching) the
132
+ plugin is needed.
133
+
134
+ ==== Time formats:
135
+ hh:nn:ss
136
+ hh-nn-ss
137
+ h:nn
138
+ h.nn
139
+ h nn
140
+ h-nn
141
+ h:nn_ampm
142
+ h.nn_ampm
143
+ h nn_ampm
144
+ h-nn_ampm
145
+ h_ampm
146
+
147
+ NOTE: Any time format without a meridian token (the 'ampm' token) is considered in 24 hour time.
148
+
149
+ ==== Date formats:
150
+ yyyy/mm/dd
151
+ yyyy-mm-dd
152
+ yyyy.mm.dd
153
+ m/d/yy OR d/m/yy
154
+ m\d\yy OR d\m\yy
155
+ d-m-yy
156
+ d.m.yy
157
+ d mmm yy
158
+
159
+ NOTE: To use non-US date formats see US/EURO FORMATS section
160
+
161
+ ==== Datetime formats:
162
+ m/d/yy h:nn:ss OR d/m/yy hh:nn:ss
163
+ m/d/yy h:nn OR d/m/yy h:nn
164
+ m/d/yy h:nn_ampm OR d/m/yy h:nn_ampm
165
+ yyyy-mm-dd hh:nn:ss
166
+ yyyy-mm-dd h:nn
167
+ ddd mmm d hh:nn:ss zo yyyy # Ruby time string
168
+ yyyy-mm-ddThh:nn:ssZ # ISO 8601 without zone offset
169
+ yyyy-mm-ddThh:nn:sszo # ISO 8601 with zone offset
170
+
171
+ NOTE: To use non-US date formats see US/EURO FORMATS section
172
+
173
+ Here is what each format token means:
174
+
175
+ Format tokens:
176
+ y = year
177
+ m = month
178
+ d = day
179
+ h = hour
180
+ n = minute
181
+ s = second
182
+ u = micro-seconds
183
+ ampm = meridian (am or pm) with or without dots (e.g. am, a.m, or a.m.)
184
+ _ = optional space
185
+ tz = Timezone abbreviation (e.g. UTC, GMT, PST, EST)
186
+ zo = Timezone offset (e.g. +10:00, -08:00, +1000)
187
+
188
+ Repeating tokens:
189
+ x = 1 or 2 digits for unit (e.g. 'h' means an hour can be '9' or '09')
190
+ xx = 2 digits exactly for unit (e.g. 'hh' means an hour can only be '09')
191
+
192
+ Special Cases:
193
+ yy = 2 or 4 digit year
194
+ yyyy = exactly 4 digit year
195
+ mmm = month long name (e.g. 'Jul' or 'July')
196
+ ddd = Day name of 3 to 9 letters (e.g. Wed or Wednesday)
197
+ u = microseconds matches 1 to 3 digits
198
+
199
+ All other characters are considered literal. For the technically minded
200
+ (well you are developers), these formats are compiled into regular expressions
201
+ at runtime so don't add any extra overhead than using regular expressions
202
+ directly. So, no, it won't make your app slow!
203
+
204
+ To see all defined formats look in lib/validates_timeliness/formats.rb.
205
+
206
+ === US/EURO FORMATS
207
+
208
+ The perenial problem for non-US developers or applications not primarily for the
209
+ US, is the US date format of m/d/yy. This is ambiguous with the European format
210
+ of d/m/yy. By default the plugin uses the US formats as this is the Ruby default
211
+ when it does date interpretation, and is in keeping PoLS (principle of least
212
+ surprise).
213
+
214
+ To switch to using the European (or Rest of The World) formats put this in an
215
+ initializer or environment.rb
216
+
217
+ ValidatesTimeliness::Formats.remove_us_formats
218
+
219
+ Now '01/02/2000' will be parsed as 1st February 2000, instead of 2nd January 2000.
220
+
221
+ === CUSTOMISING FORMATS:
222
+
223
+ I hear you say "Thats greats but I don't want X format to be valid". Well to
224
+ remove a format stick this in an initializer file
225
+
226
+ ValidatesTimeliness::Formats.remove_formats(:date, 'm\d\yy')
227
+
228
+ Done! That format is no longer considered valid. Easy!
229
+
230
+ Ok, now I hear you say "Well I have format that I want to use but you don't have it".
231
+ Ahh, then add it yourself. Again stick this in an initializer file
232
+
233
+ ValidatesTimeliness::Formats.add_formats(:time, "d o'clock")
234
+
235
+ Now "10 o'clock" will be a valid value. So easy, no more whingeing!
236
+
237
+ You can embed regular expressions in the format but no gurantees that it will
238
+ remain intact. If you avoid the use of any token characters and regexp dots or
239
+ backslashes as special characters in the regexp, it may well work as expected.
240
+ For special characters use POSIX character classes for safety. See the ISO 8601
241
+ datetime for an example of an embedded regular expression.
242
+
243
+ Because formats are evaluated in order, adding a format which may be ambiguous
244
+ with an existing format, will mean your format is ignored. If you need to make
245
+ your new format higher precedence than an existing format, you can include the
246
+ before option like so
247
+
248
+ ValidatesTimeliness::Formats.add_formats(:time, 'ss:nn:hh', :before => 'hh:nn:ss')
249
+
250
+ Now a time of '59:30:23' will be interpreted as 11:30:59 pm. This option saves
251
+ you adding a new one and deleting an old one to get it to work.
252
+
253
+
254
+ === AMBIGUOUS YEAR THRESHOLD
255
+
256
+ When dealing with 2 digit year values, by default a year is interpreted as being
257
+ in the last century at or above 30. You can customize this however
258
+
259
+ ValidatesTimeliness::Formats.ambiguous_year_threshold = 20
260
+
261
+ Now you get:
262
+
263
+ year of 19 is considered 2019
264
+ year of 20 is considered 1920
265
+
266
+
267
+ === DUMMY DATE FOR TIME TYPES
268
+
269
+ Given that Ruby has no support for a time-only type, all time type columns are evaluated
270
+ as a regular Time class objects with a dummy date value set. Rails defines the dummy date as
271
+ 2000-01-01. So a time of '12:30' is evaluated as a Time value of '2000-01-01 12:30'. If you
272
+ need to customize this for some reason you can do so as follows
273
+
274
+ ValidatesTimeliness::Formats.dummy_date_for_time_type = [2009, 1, 1]
275
+
276
+ The value should be an array of 3 values being year, month and day in that order.
277
+
278
+
279
+ === TEMPORAL RESTRICTION ERRORS:
280
+
281
+ When using the validation temporal restrictions there are times when the restriction
282
+ value itself may be invalid. Normally this will add an error to the model such as
283
+ 'restriction :before value was invalid'. These can be annoying if you are using
284
+ procs or methods as restrictions and don't care if they don't evaluate properly
285
+ and you want the validation to complete. In these situations you turn them off.
286
+
287
+ To turn them off:
288
+
289
+ ValidatesTimeliness::Validator.ignore_restriction_errors = true
290
+
291
+ A word of warning though, as this may hide issues with the model and make those
292
+ corner cases a little harder to test. In general if you are using procs or
293
+ model methods and you only care when they return a value, then they should
294
+ return nil in all other situations. Restrictions are skipped if they are nil.
295
+
296
+
297
+ === DISPLAY INVALID VALUES IN DATE HELPERS:
298
+
299
+ The plugin has some extensions to ActionView and ActiveRecord by allowing invalid
300
+ date and time values to be redisplayed to the user as feedback, instead of
301
+ a blank field which happens by default in Rails. Though the date helpers make this a
302
+ pretty rare occurence, given the select dropdowns for each date/time component, but
303
+ it may be something of interest.
304
+
305
+ To activate it, put this in an initializer:
306
+
307
+ ValidatesTimeliness.enable_datetime_select_extension!
308
+
309
+ This will be removed from v3 as it adds too little to maintain.
310
+
311
+ === OTHER CUSTOMISATION:
312
+
313
+ The error messages for each temporal restrictions can also be globally overridden by
314
+ updating the default AR error messages like so
315
+
316
+ For Rails 2.0/2.1:
317
+
318
+ ActiveRecord::Errors.default_error_messages.update(
319
+ :invalid_date => "is not a valid date",
320
+ :invalid_time => "is not a valid time",
321
+ :invalid_datetime => "is not a valid datetime",
322
+ :is_at => "must be at %s",
323
+ :before => "must be before %s",
324
+ :on_or_before => "must be on or before %s",
325
+ :after => "must be after %s",
326
+ :on_or_after => "must be on or after %s",
327
+ :between => "must be between %s and %s"
328
+ )
329
+
330
+ Where %s is the interpolation value for the restriction.
331
+
332
+ Rails 2.2+ using the I18n system to define new defaults:
333
+
334
+ en:
335
+ activerecord:
336
+ errors:
337
+ messages:
338
+ invalid_date: "is not a valid date"
339
+ invalid_time: "is not a valid time"
340
+ invalid_datetime: "is not a valid datetime"
341
+ is_at: "must be at {{restriction}}"
342
+ before: "must be before {{restriction}}"
343
+ on_or_before: "must be on or before {{restriction}}"
344
+ after: "must be after {{restriction}}"
345
+ on_or_after: "must be on or after {{restriction}}"
346
+ between: "must be between {{earliest}} and {{latest}}"
347
+
348
+ The {{restriction}} signifies where the interpolation value for the restriction
349
+ will be inserted.
350
+
351
+ And for something a little more specific you can override the format of the interpolation
352
+ values inserted in the error messages for temporal restrictions like so
353
+
354
+ For Rails 2.0/2.1:
355
+
356
+ ValidatesTimeliness::Validator.error_value_formats.update(
357
+ :time => '%H:%M:%S',
358
+ :date => '%Y-%m-%d',
359
+ :datetime => '%Y-%m-%d %H:%M:%S'
360
+ )
361
+
362
+ Rails 2.2+ using the I18n system to define new defaults:
363
+
364
+ validates_timeliness:
365
+ error_value_formats:
366
+ date: '%Y-%m-%d'
367
+ time: '%H:%M:%S'
368
+ datetime: '%Y-%m-%d %H:%M:%S'
369
+
370
+ Those are Ruby strftime formats not the plugin formats.
371
+
372
+
373
+ === RSPEC MATCHER:
374
+
375
+ To sweeten the deal that little bit more, you have an Rspec matcher available for
376
+ you model specs. Now you can easily test the validations you have just written
377
+ with the plugin or better yet *before* you write them! You just use the
378
+ validation options you want as you would with the validation method. Those
379
+ options are then verified and reported if they fail.
380
+
381
+ First require it in your spec_helper.rb
382
+
383
+ require 'validates_timeliness/matcher'
384
+
385
+ Use it like so:
386
+
387
+ @person.should validate_date(:birth_date, :before => Time.now, :before_message => 'should be before today')
388
+
389
+
390
+ The matcher names are just the singular of the validation methods.
391
+
392
+ == CREDITS:
393
+
394
+ * Adam Meehan (adam.meehan@gmail.com, http://duckpunching.com/)
395
+
396
+ * Jonathan Viney (http://workingwithrails.com/person/4985-jonathan-viney)
397
+ For his validates_date_time plugin which I have used up until this plugin and
398
+ which influenced some of the design and I borrowed a little of code from it.
399
+
400
+
401
+ == LICENSE:
402
+
403
+ Copyright (c) 2008-2010 Adam Meehan, released under the MIT license