validates_timeliness 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +30 -21
- data/lib/validates_timeliness/attribute_methods.rb +6 -2
- data/lib/validates_timeliness/version.rb +1 -1
- data/spec/spec_helper.rb +7 -0
- data/spec/validates_timeliness/attribute_methods_spec.rb +6 -0
- data/validates_timeliness.gemspec +2 -2
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -18,9 +18,9 @@ If you a looking for the old version for Rails 2.x go here[http://github.com/adz
|
|
18
18
|
|
19
19
|
* Only Rails date/time validation plugin offering complete validation (See ORM/ODM support)
|
20
20
|
|
21
|
-
* Adds extensions to fix Rails date/time select issues
|
21
|
+
* Adds extensions to fix Rails date/time select issues (See Extensions)
|
22
22
|
|
23
|
-
* Uses extensible date/time parser ({timeliness gem}[http://github.com/adzap/timeliness])
|
23
|
+
* Uses extensible date/time parser (Using {timeliness gem}[http://github.com/adzap/timeliness]. See Plugin Parser)
|
24
24
|
|
25
25
|
* Supports I18n for the error messages
|
26
26
|
|
@@ -31,7 +31,7 @@ As plugin (from master)
|
|
31
31
|
|
32
32
|
rails plugin install git://github.com/adzap/validates_timeliness.git
|
33
33
|
|
34
|
-
As gem
|
34
|
+
As gem
|
35
35
|
|
36
36
|
# in Gemfile
|
37
37
|
gem 'validates_timeliness', '~> 3.0.0'
|
@@ -46,6 +46,8 @@ Then run
|
|
46
46
|
This creates configuration initializer and locale files. In the initializer, you there are a number of config
|
47
47
|
options to customize the plugin.
|
48
48
|
|
49
|
+
NOTE: You may wish to enable the plugin parser and the extensions to start. Please read those sections first.
|
50
|
+
|
49
51
|
|
50
52
|
== Examples
|
51
53
|
|
@@ -175,7 +177,8 @@ You can also use validation options for custom error messages. The following opt
|
|
175
177
|
:after_message
|
176
178
|
:on_or_after_message
|
177
179
|
|
178
|
-
Note: There is no :between_message option. The between error message should be defined using the
|
180
|
+
Note: There is no :between_message option. The between error message should be defined using the
|
181
|
+
:on_or_before and :on_or_after messages.
|
179
182
|
|
180
183
|
It is highly recommended you use the I18n system for error messages.
|
181
184
|
|
@@ -254,36 +257,42 @@ To turn them on/off:
|
|
254
257
|
config.ignore_restriction_errors = true
|
255
258
|
|
256
259
|
|
257
|
-
|
260
|
+
== Extensions
|
258
261
|
|
259
|
-
|
260
|
-
date and time values to be redisplayed to the user as feedback, instead of
|
261
|
-
a blank field which happens by default in Rails. Though the date helpers make this a
|
262
|
-
pretty rare occurrence, given the select dropdowns for each date/time component, but
|
263
|
-
it may be something of interest.
|
262
|
+
=== Strict Parsing for Select Helpers
|
264
263
|
|
265
|
-
|
264
|
+
When using date/time select helpers, the component values are handled by ActiveRecord using
|
265
|
+
the Time class to instantiate them into a time value. This means that some invalid dates,
|
266
|
+
such as 31st June, are shifted forward and treated as valid. To handle these cases in a strict
|
267
|
+
way, you can enable the plugin extension to treat them as invalid dates.
|
268
|
+
|
269
|
+
To activate it, uncomment this line in the initializer:
|
266
270
|
|
267
271
|
# in the setup block
|
268
|
-
config.
|
272
|
+
config.enable_multiparameter_extension!
|
269
273
|
|
270
274
|
|
271
|
-
===
|
275
|
+
=== Display Invalid Values in Select Helpers
|
272
276
|
|
273
|
-
|
274
|
-
the
|
275
|
-
|
276
|
-
|
277
|
+
The plugin offers an extension for ActionView to allowing invalid date and time values to be
|
278
|
+
redisplayed to the user as feedback, instead of a blank field which happens by default in
|
279
|
+
Rails. Though the date helpers make this a pretty rare occurrence, given the select dropdowns
|
280
|
+
for each date/time component, but it may be something of interest.
|
277
281
|
|
278
|
-
To activate it,
|
282
|
+
To activate it, uncomment this line in the initializer:
|
279
283
|
|
280
284
|
# in the setup block
|
281
|
-
config.
|
285
|
+
config.enable_date_time_select_extension!
|
286
|
+
|
287
|
+
|
288
|
+
== Contributors
|
289
|
+
|
290
|
+
To see the generous people who have contributed code, take a look at the {contributors list}[http://github.com/adzap/validates_timeliness/contributors].
|
282
291
|
|
283
292
|
|
284
|
-
==
|
293
|
+
== Maintainers
|
285
294
|
|
286
|
-
* Adam Meehan
|
295
|
+
* {Adam Meehan}[http://github.com/adzap]
|
287
296
|
|
288
297
|
|
289
298
|
== License
|
@@ -42,7 +42,7 @@ module ValidatesTimeliness
|
|
42
42
|
super
|
43
43
|
end
|
44
44
|
EOV
|
45
|
-
|
45
|
+
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
46
46
|
end
|
47
47
|
|
48
48
|
def define_timeliness_before_type_cast_method(attr_name)
|
@@ -51,7 +51,11 @@ module ValidatesTimeliness
|
|
51
51
|
_timeliness_raw_value_for('#{attr_name}')
|
52
52
|
end
|
53
53
|
EOV
|
54
|
-
|
54
|
+
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
55
|
+
end
|
56
|
+
|
57
|
+
def generated_timeliness_methods
|
58
|
+
@generated_timeliness_methods ||= Module.new.tap { |m| include(m) }
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
data/spec/spec_helper.rb
CHANGED
@@ -75,6 +75,13 @@ class Employee < ActiveRecord::Base
|
|
75
75
|
validates_time :birth_time
|
76
76
|
validates_datetime :birth_datetime
|
77
77
|
define_attribute_methods
|
78
|
+
|
79
|
+
attr_accessor :redefined_birth_date_called
|
80
|
+
|
81
|
+
def birth_date=(value)
|
82
|
+
self.redefined_birth_date_called = true
|
83
|
+
super
|
84
|
+
end
|
78
85
|
end
|
79
86
|
|
80
87
|
Rspec.configure do |c|
|
@@ -34,6 +34,12 @@ describe ValidatesTimeliness::AttributeMethods do
|
|
34
34
|
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'should not overwrite user defined methods' do
|
38
|
+
e = Employee.new
|
39
|
+
e.birth_date = '2010-01-01'
|
40
|
+
e.redefined_birth_date_called.should be_true
|
41
|
+
end
|
42
|
+
|
37
43
|
context "with plugin parser" do
|
38
44
|
class PersonWithParser
|
39
45
|
include TestModel
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{validates_timeliness}
|
5
|
-
s.version = "3.0.
|
5
|
+
s.version = "3.0.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Adam Meehan"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-11-02}
|
10
10
|
s.description = %q{Date and time validation plugin for Rails which allows custom formats}
|
11
11
|
s.email = %q{adam.meehan@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_timeliness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.
|
9
|
+
- 1
|
10
|
+
version: 3.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Meehan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-02 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|