validates_timeliness 3.0.12 → 3.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Appraisals +11 -0
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +9 -14
- data/Rakefile +4 -2
- data/gemfiles/rails_3_0.gemfile +15 -0
- data/gemfiles/rails_3_1.gemfile +15 -0
- data/gemfiles/rails_3_2.gemfile +15 -0
- data/lib/validates_timeliness/orm/active_record.rb +13 -44
- data/lib/validates_timeliness/validator.rb +4 -0
- data/lib/validates_timeliness/version.rb +1 -1
- data/spec/spec_helper.rb +3 -6
- data/spec/validates_timeliness/orm/active_record_spec.rb +104 -22
- metadata +8 -4
data/Appraisals
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
= 3.0.13 [2012-08-21]
|
2
|
+
* Fix ActiveRecord issues with using plugin parser by using old way of caching values.
|
3
|
+
* Allow any ActiveRecord non-column attribute to be validated
|
4
|
+
|
1
5
|
= 3.0.12 [2012-06-23]
|
2
6
|
* Fix load order issue when relying on Railtie to load ActiveRecord extension
|
3
7
|
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= ValidatesTimeliness
|
2
2
|
|
3
3
|
* Source: http://github.com/adzap/validates_timeliness
|
4
|
-
*
|
4
|
+
* Issues: http://github.com/adzap/validates_timeliness/issues
|
5
5
|
|
6
6
|
== Description
|
7
7
|
|
@@ -18,24 +18,19 @@ 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 (See Extensions)
|
22
|
-
|
23
21
|
* Uses extensible date/time parser (Using {timeliness gem}[http://github.com/adzap/timeliness]. See Plugin Parser)
|
24
22
|
|
25
|
-
*
|
26
|
-
|
27
|
-
* Supports Ruby 1.8.x, 1.9.x and Rubinius.
|
23
|
+
* Adds extensions to fix Rails date/time select issues (See Extensions)
|
28
24
|
|
29
|
-
|
25
|
+
* Supports I18n for the error messages
|
30
26
|
|
31
|
-
|
27
|
+
* Supports all the Rubies (that any sane person would be using in production).
|
32
28
|
|
33
|
-
rails plugin install git://github.com/adzap/validates_timeliness.git
|
34
29
|
|
35
|
-
|
30
|
+
== Installation
|
36
31
|
|
37
32
|
# in Gemfile
|
38
|
-
gem 'validates_timeliness', '~> 3.0
|
33
|
+
gem 'validates_timeliness', '~> 3.0'
|
39
34
|
|
40
35
|
# Run bundler
|
41
36
|
$ bundle install
|
@@ -55,7 +50,7 @@ NOTE: You may wish to enable the plugin parser and the extensions to start. Plea
|
|
55
50
|
validates_datetime :occurred_at
|
56
51
|
|
57
52
|
validates_date :date_of_birth, :before => lambda { 18.years.ago },
|
58
|
-
|
53
|
+
:before_message => "must be at least 18 years old"
|
59
54
|
|
60
55
|
validates_datetime :finish_time, :after => :start_time # Method symbol
|
61
56
|
|
@@ -79,7 +74,7 @@ validation method
|
|
79
74
|
validates :date_of_birth, :timeliness => {:on_or_before => lambda { Date.current }, :type => :date}
|
80
75
|
end
|
81
76
|
|
82
|
-
|
77
|
+
or even on a specific record, per ActiveModel API.
|
83
78
|
|
84
79
|
@person.validates_date :date_of_birth, :on_or_before => lambda { Date.current }
|
85
80
|
|
@@ -298,4 +293,4 @@ To see the generous people who have contributed code, take a look at the {contri
|
|
298
293
|
|
299
294
|
== License
|
300
295
|
|
301
|
-
Copyright (c) 2008
|
296
|
+
Copyright (c) 2008 Adam Meehan, released under the MIT license
|
data/Rakefile
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "rspec", "~> 2.8"
|
6
|
+
gem "rspec-rails", "~> 2.8"
|
7
|
+
gem "timecop"
|
8
|
+
gem "rspec_tag_matchers"
|
9
|
+
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
10
|
+
gem "debugger", :platforms=>[:ruby_19]
|
11
|
+
gem "appraisal"
|
12
|
+
gem "sqlite3"
|
13
|
+
gem "rails", "~> 3.0.0"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "rspec", "~> 2.8"
|
6
|
+
gem "rspec-rails", "~> 2.8"
|
7
|
+
gem "timecop"
|
8
|
+
gem "rspec_tag_matchers"
|
9
|
+
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
10
|
+
gem "debugger", :platforms=>[:ruby_19]
|
11
|
+
gem "appraisal"
|
12
|
+
gem "sqlite3"
|
13
|
+
gem "rails", "~> 3.1.0"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "rspec", "~> 2.8"
|
6
|
+
gem "rspec-rails", "~> 2.8"
|
7
|
+
gem "timecop"
|
8
|
+
gem "rspec_tag_matchers"
|
9
|
+
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
10
|
+
gem "debugger", :platforms=>[:ruby_19]
|
11
|
+
gem "appraisal"
|
12
|
+
gem "sqlite3"
|
13
|
+
gem "rails", "~> 3.2.0"
|
14
|
+
|
15
|
+
gemspec :path=>"../"
|
@@ -3,60 +3,31 @@ module ValidatesTimeliness
|
|
3
3
|
module ActiveRecord
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
def self.use_plugin_cache?
|
7
|
-
::ActiveRecord::VERSION::STRING < '3.1.0'
|
8
|
-
end
|
9
|
-
|
10
|
-
included do
|
11
|
-
if ValidatesTimeliness::ORM::ActiveRecord.use_plugin_cache?
|
12
|
-
include Reload
|
13
|
-
else
|
14
|
-
# Just use the built-in before_type_cast retrieval
|
15
|
-
alias_method :_timeliness_raw_value_for, :read_attribute_before_type_cast
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
6
|
module ClassMethods
|
20
7
|
public
|
21
8
|
|
22
9
|
def timeliness_attribute_timezone_aware?(attr_name)
|
23
|
-
attr_name
|
24
|
-
create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
|
10
|
+
create_time_zone_conversion_attribute?(attr_name, timeliness_column_for_attribute(attr_name))
|
25
11
|
end
|
26
12
|
|
27
13
|
def timeliness_attribute_type(attr_name)
|
28
|
-
|
14
|
+
timeliness_column_for_attribute(attr_name).type
|
29
15
|
end
|
30
16
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
17
|
+
def timeliness_column_for_attribute(attr_name)
|
18
|
+
columns_hash.fetch(attr_name.to_s) do |attr_name|
|
19
|
+
validation_type = _validators[attr_name.to_sym].find {|v| v.kind == :timeliness }.type
|
20
|
+
::ActiveRecord::ConnectionAdapters::Column.new(attr_name, nil, validation_type.to_s)
|
35
21
|
end
|
36
22
|
end
|
37
23
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
if before_type_cast
|
42
|
-
define_timeliness_write_method(attr_name)
|
43
|
-
define_timeliness_before_type_cast_method(attr_name)
|
44
|
-
elsif ValidatesTimeliness.use_plugin_parser
|
45
|
-
define_timeliness_write_method_without_cache(attr_name)
|
24
|
+
def define_attribute_methods
|
25
|
+
super.tap do |attribute_methods_generated|
|
26
|
+
define_timeliness_methods true
|
46
27
|
end
|
47
28
|
end
|
48
29
|
|
49
|
-
|
50
|
-
method_body, line = <<-EOV, __LINE__ + 1
|
51
|
-
def #{attr_name}=(value)
|
52
|
-
original_value = value
|
53
|
-
if value.is_a?(String)\n#{timeliness_type_cast_code(attr_name, 'value')}\nend
|
54
|
-
super(value)
|
55
|
-
@attributes['#{attr_name}'] = original_value
|
56
|
-
end
|
57
|
-
EOV
|
58
|
-
generated_timeliness_methods.module_eval(method_body, __FILE__, line)
|
59
|
-
end
|
30
|
+
protected
|
60
31
|
|
61
32
|
def timeliness_type_cast_code(attr_name, var_name)
|
62
33
|
type = timeliness_attribute_type(attr_name)
|
@@ -67,11 +38,9 @@ module ValidatesTimeliness
|
|
67
38
|
end
|
68
39
|
end
|
69
40
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
super
|
74
|
-
end
|
41
|
+
def reload(*args)
|
42
|
+
_clear_timeliness_cache
|
43
|
+
super
|
75
44
|
end
|
76
45
|
|
77
46
|
end
|
@@ -22,6 +22,10 @@ module ValidatesTimeliness
|
|
22
22
|
|
23
23
|
RESTRICTION_ERROR_MESSAGE = "Error occurred validating %s for %s restriction:\n%s"
|
24
24
|
|
25
|
+
def self.kind
|
26
|
+
:timeliness
|
27
|
+
end
|
28
|
+
|
25
29
|
def initialize(options)
|
26
30
|
@type = options.delete(:type) || :datetime
|
27
31
|
@allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank)
|
data/spec/spec_helper.rb
CHANGED
@@ -92,10 +92,7 @@ RSpec.configure do |c|
|
|
92
92
|
reset_validation_setup_for(PersonWithShim)
|
93
93
|
end
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
99
|
-
end
|
100
|
-
|
95
|
+
c.filter_run_excluding :active_record => lambda {|version|
|
96
|
+
!(::ActiveRecord::VERSION::STRING.to_s =~ /^#{version.to_s}/)
|
97
|
+
}
|
101
98
|
end
|
@@ -41,13 +41,44 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should determine type for attribute' do
|
44
|
-
Employee.timeliness_attribute_type(:birth_date).should
|
44
|
+
Employee.timeliness_attribute_type(:birth_date).should eq :date
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'attribute timezone awareness' do
|
48
|
+
let(:klass) {
|
49
|
+
Class.new(ActiveRecord::Base) do
|
50
|
+
self.table_name = 'employees'
|
51
|
+
attr_accessor :some_date
|
52
|
+
attr_accessor :some_time
|
53
|
+
attr_accessor :some_datetime
|
54
|
+
validates_date :some_date
|
55
|
+
validates_time :some_time
|
56
|
+
validates_datetime :some_datetime
|
57
|
+
end
|
58
|
+
}
|
59
|
+
|
60
|
+
context 'for column attribute' do
|
61
|
+
it 'should be detected from column type' do
|
62
|
+
klass.timeliness_attribute_timezone_aware?(:birth_date).should be_false
|
63
|
+
klass.timeliness_attribute_timezone_aware?(:birth_time).should be_false
|
64
|
+
klass.timeliness_attribute_timezone_aware?(:birth_datetime).should be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'for non-column attribute' do
|
69
|
+
it 'should be detected from the validation type' do
|
70
|
+
klass.timeliness_attribute_timezone_aware?(:some_date).should be_false
|
71
|
+
klass.timeliness_attribute_timezone_aware?(:some_time).should be_false
|
72
|
+
klass.timeliness_attribute_timezone_aware?(:some_datetime).should be_true
|
73
|
+
end
|
74
|
+
end
|
45
75
|
end
|
46
76
|
|
47
77
|
context "attribute write method" do
|
48
78
|
class EmployeeWithCache < ActiveRecord::Base
|
49
|
-
|
79
|
+
self.table_name = 'employees'
|
50
80
|
validates_date :birth_date, :allow_blank => true
|
81
|
+
validates_time :birth_time, :allow_blank => true
|
51
82
|
validates_datetime :birth_datetime, :allow_blank => true
|
52
83
|
end
|
53
84
|
|
@@ -55,8 +86,9 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
55
86
|
context 'for datetime column' do
|
56
87
|
it 'should store raw value' do
|
57
88
|
r = EmployeeWithCache.new
|
58
|
-
r.birth_datetime =
|
59
|
-
|
89
|
+
r.birth_datetime = datetime_string = '2010-01-01 12:30'
|
90
|
+
|
91
|
+
r._timeliness_raw_value_for('birth_datetime').should eq datetime_string
|
60
92
|
end
|
61
93
|
end
|
62
94
|
|
@@ -64,7 +96,17 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
64
96
|
it 'should store raw value' do
|
65
97
|
r = EmployeeWithCache.new
|
66
98
|
r.birth_date = date_string = '2010-01-01'
|
67
|
-
|
99
|
+
|
100
|
+
r._timeliness_raw_value_for('birth_date').should eq date_string
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'for time column' do
|
105
|
+
it 'should store raw value' do
|
106
|
+
r = EmployeeWithCache.new
|
107
|
+
r.birth_time = time_string = '12:12'
|
108
|
+
|
109
|
+
r._timeliness_raw_value_for('birth_time').should eq time_string
|
68
110
|
end
|
69
111
|
end
|
70
112
|
end
|
@@ -73,36 +115,76 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
73
115
|
with_config(:use_plugin_parser, true)
|
74
116
|
|
75
117
|
class EmployeeWithParser < ActiveRecord::Base
|
76
|
-
|
118
|
+
self.table_name = 'employees'
|
77
119
|
validates_date :birth_date, :allow_blank => true
|
120
|
+
validates_time :birth_time, :allow_blank => true
|
78
121
|
validates_datetime :birth_datetime, :allow_blank => true
|
79
122
|
end
|
80
123
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
r.birth_date = '2010-01-01'
|
85
|
-
end
|
124
|
+
context "for a date column" do
|
125
|
+
it 'should parse a string value' do
|
126
|
+
Timeliness::Parser.should_receive(:parse)
|
86
127
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
r.birth_date = 'not a date'
|
91
|
-
end
|
128
|
+
r = EmployeeWithParser.new
|
129
|
+
r.birth_date = '2010-01-01'
|
130
|
+
end
|
92
131
|
|
93
|
-
|
94
|
-
|
132
|
+
it 'should parse a invalid string value as nil' do
|
133
|
+
Timeliness::Parser.should_receive(:parse)
|
134
|
+
r = EmployeeWithParser.new
|
135
|
+
r.birth_date = 'not valid'
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should store a Date value after parsing string' do
|
95
139
|
r = EmployeeWithParser.new
|
96
140
|
r.birth_date = '2010-01-01'
|
97
141
|
|
98
142
|
r.birth_date.should be_kind_of(Date)
|
99
|
-
r.birth_date.should
|
143
|
+
r.birth_date.should eq Date.new(2010, 1, 1)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "for a time column" do
|
148
|
+
it 'should parse a string value' do
|
149
|
+
Timeliness::Parser.should_receive(:parse)
|
150
|
+
|
151
|
+
r = EmployeeWithParser.new
|
152
|
+
r.birth_time = '12:30'
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should parse a invalid string value as nil' do
|
156
|
+
Timeliness::Parser.should_receive(:parse)
|
157
|
+
|
158
|
+
r = EmployeeWithParser.new
|
159
|
+
r.birth_time = 'not valid'
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should store a Time value after parsing string' do
|
163
|
+
r = EmployeeWithParser.new
|
164
|
+
r.birth_time = '12:30'
|
165
|
+
|
166
|
+
r.birth_time.should be_kind_of(Time)
|
167
|
+
r.birth_time.should eq Time.utc(2000, 1, 1, 12, 30)
|
100
168
|
end
|
101
169
|
end
|
102
170
|
|
103
171
|
context "for a datetime column" do
|
104
172
|
with_config(:default_timezone, 'Australia/Melbourne')
|
105
173
|
|
174
|
+
it 'should parse a string value' do
|
175
|
+
Timeliness::Parser.should_receive(:parse)
|
176
|
+
|
177
|
+
r = EmployeeWithParser.new
|
178
|
+
r.birth_datetime = '2010-01-01 12:00'
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should parse a invalid string value as nil' do
|
182
|
+
Timeliness::Parser.should_receive(:parse)
|
183
|
+
|
184
|
+
r = EmployeeWithParser.new
|
185
|
+
r.birth_datetime = 'not valid'
|
186
|
+
end
|
187
|
+
|
106
188
|
it 'should parse string into Time value' do
|
107
189
|
r = EmployeeWithParser.new
|
108
190
|
r.birth_datetime = '2010-01-01 12:00'
|
@@ -114,7 +196,7 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
114
196
|
r = EmployeeWithParser.new
|
115
197
|
r.birth_datetime = '2010-06-01 12:00'
|
116
198
|
|
117
|
-
r.birth_datetime.utc_offset.should
|
199
|
+
r.birth_datetime.utc_offset.should eq Time.zone.utc_offset
|
118
200
|
end
|
119
201
|
end
|
120
202
|
end
|
@@ -140,7 +222,7 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
140
222
|
r = Employee.new
|
141
223
|
r.birth_datetime = date_string = '2010-01-01'
|
142
224
|
|
143
|
-
r.birth_datetime_before_type_cast.should
|
225
|
+
r.birth_datetime_before_type_cast.should eq date_string
|
144
226
|
end
|
145
227
|
|
146
228
|
it 'should return attribute if no attribute assignment has been made' do
|
@@ -158,7 +240,7 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
|
158
240
|
r = Employee.new
|
159
241
|
r.birth_datetime = date_string = '2010-01-31'
|
160
242
|
|
161
|
-
r.birth_datetime_before_type_cast.should
|
243
|
+
r.birth_datetime_before_type_cast.should eq date_string
|
162
244
|
end
|
163
245
|
end
|
164
246
|
|
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: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.
|
9
|
+
- 13
|
10
|
+
version: 3.0.13
|
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: 2012-
|
18
|
+
date: 2012-08-21 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -45,10 +45,14 @@ extra_rdoc_files:
|
|
45
45
|
- CHANGELOG.rdoc
|
46
46
|
- LICENSE
|
47
47
|
files:
|
48
|
+
- Appraisals
|
48
49
|
- CHANGELOG.rdoc
|
49
50
|
- LICENSE
|
50
51
|
- README.rdoc
|
51
52
|
- Rakefile
|
53
|
+
- gemfiles/rails_3_0.gemfile
|
54
|
+
- gemfiles/rails_3_1.gemfile
|
55
|
+
- gemfiles/rails_3_2.gemfile
|
52
56
|
- init.rb
|
53
57
|
- lib/generators/validates_timeliness/install_generator.rb
|
54
58
|
- lib/generators/validates_timeliness/templates/en.yml
|