validates_timeliness 3.0.9 → 3.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ = 3.0.10 [2012-03-26]
2
+ * Fix for ActiveRecord shim and validation with :allow_blank => true in AR 3.1+. Fixes issue#52.
3
+
1
4
  = 3.0.9 [2012-03-26]
2
5
  * ActiveRecord 3.1+ suport
3
6
  * Fixes for multiparameter extension with empty date values (thanks @mogox, @Sharagoz)
@@ -82,7 +82,7 @@ module ValidatesTimeliness
82
82
  end
83
83
 
84
84
  def _timeliness_raw_value_for(attr_name)
85
- @timeliness_cache && @timeliness_cache[attr_name.to_s]
85
+ @timeliness_cache && @timeliness_cache[attr_name]
86
86
  end
87
87
 
88
88
  def _clear_timeliness_cache
@@ -77,7 +77,7 @@ module ValidatesTimeliness
77
77
 
78
78
  def attribute_raw_value(record, attr_name)
79
79
  record.respond_to?(:_timeliness_raw_value_for) &&
80
- record._timeliness_raw_value_for(attr_name)
80
+ record._timeliness_raw_value_for(attr_name.to_s)
81
81
  end
82
82
 
83
83
  def timezone_aware?(record, attr_name)
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '3.0.9'
2
+ VERSION = '3.0.10'
3
3
  end
@@ -14,6 +14,30 @@ describe ValidatesTimeliness, 'ActiveRecord' do
14
14
  Employee.new.should respond_to(:validates_time)
15
15
  Employee.new.should respond_to(:validates_datetime)
16
16
  end
17
+
18
+ it "should validate a valid value string" do
19
+ r = Employee.new
20
+ r.birth_date = '2012-01-01'
21
+
22
+ r.valid?
23
+ r.errors[:birth_date].should be_empty
24
+ end
25
+
26
+ it "should validate a invalid value string" do
27
+ r = Employee.new
28
+ r.birth_date = 'not a date'
29
+
30
+ r.valid?
31
+ r.errors[:birth_date].should_not be_empty
32
+ end
33
+
34
+ it "should validate a nil value" do
35
+ r = Employee.new
36
+ r.birth_date = nil
37
+
38
+ r.valid?
39
+ r.errors[:birth_date].should be_empty
40
+ end
17
41
  end
18
42
 
19
43
  it 'should determine type for attribute' do
@@ -23,13 +47,26 @@ describe ValidatesTimeliness, 'ActiveRecord' do
23
47
  context "attribute write method" do
24
48
  class EmployeeWithCache < ActiveRecord::Base
25
49
  set_table_name 'employees'
26
- validates_datetime :birth_datetime
50
+ validates_date :birth_date, :allow_blank => true
51
+ validates_datetime :birth_datetime, :allow_blank => true
27
52
  end
28
53
 
29
- it 'should cache attribute raw value' do
30
- r = EmployeeWithCache.new
31
- r.birth_datetime = date_string = '2010-01-01'
32
- r._timeliness_raw_value_for('birth_datetime').should == date_string
54
+ context 'value cache' do
55
+ context 'for datetime column' do
56
+ it 'should store raw value' do
57
+ r = EmployeeWithCache.new
58
+ r.birth_datetime = date_string = '2010-01-01'
59
+ r._timeliness_raw_value_for('birth_datetime').should == date_string
60
+ end
61
+ end
62
+
63
+ context 'for date column' do
64
+ it 'should store raw value' do
65
+ r = EmployeeWithCache.new
66
+ r.birth_date = date_string = '2010-01-01'
67
+ r._timeliness_raw_value_for('birth_date').should == date_string
68
+ end
69
+ end
33
70
  end
34
71
 
35
72
  context "with plugin parser" do
@@ -37,8 +74,8 @@ describe ValidatesTimeliness, 'ActiveRecord' do
37
74
 
38
75
  class EmployeeWithParser < ActiveRecord::Base
39
76
  set_table_name 'employees'
40
- validates_date :birth_date
41
- validates_datetime :birth_datetime
77
+ validates_date :birth_date, :allow_blank => true
78
+ validates_datetime :birth_datetime, :allow_blank => true
42
79
  end
43
80
 
44
81
  it 'should parse a string value' do
@@ -47,7 +84,13 @@ describe ValidatesTimeliness, 'ActiveRecord' do
47
84
  r.birth_date = '2010-01-01'
48
85
  end
49
86
 
50
- context "for a date column", :active_record => '3.0' do
87
+ it 'should parse a invalid string value as nil' do
88
+ Timeliness::Parser.should_receive(:parse)
89
+ r = EmployeeWithParser.new
90
+ r.birth_date = 'not a date'
91
+ end
92
+
93
+ context "for a date column" do
51
94
  it 'should store a date value after parsing string' do
52
95
  r = EmployeeWithParser.new
53
96
  r.birth_date = '2010-01-01'
@@ -77,10 +120,11 @@ describe ValidatesTimeliness, 'ActiveRecord' do
77
120
  end
78
121
  end
79
122
 
80
- context "cached value" do
81
- it 'should be cleared on reload' do
123
+ context "reload" do
124
+ it 'should clear cache value' do
82
125
  r = Employee.create!
83
126
  r.birth_date = '2010-01-01'
127
+
84
128
  r.reload
85
129
 
86
130
  r._timeliness_raw_value_for('birth_date').should be_nil
@@ -38,6 +38,30 @@ describe ValidatesTimeliness, 'Mongoid' do
38
38
  Article.new.should respond_to(:validates_time)
39
39
  Article.new.should respond_to(:validates_datetime)
40
40
  end
41
+
42
+ it "should validate a valid value string" do
43
+ r = Article.new
44
+ r.publish_date = '2012-01-01'
45
+
46
+ r.valid?
47
+ r.errors[:publish_date].should be_empty
48
+ end
49
+
50
+ it "should validate a invalid value string" do
51
+ r = Article.new
52
+ r.publish_date = 'not a date'
53
+
54
+ r.valid?
55
+ r.errors[:publish_date].should_not be_empty
56
+ end
57
+
58
+ it "should validate a nil value" do
59
+ r = Article.new
60
+ r.publish_date = nil
61
+
62
+ r.valid?
63
+ r.errors[:publish_date].should be_empty
64
+ end
41
65
  end
42
66
 
43
67
  it 'should determine type for attribute' do
@@ -48,7 +72,7 @@ describe ValidatesTimeliness, 'Mongoid' do
48
72
  it 'should cache attribute raw value' do
49
73
  r = Article.new
50
74
  r.publish_datetime = date_string = '2010-01-01'
51
- r._timeliness_raw_value_for(:publish_datetime).should == date_string
75
+ r._timeliness_raw_value_for('publish_datetime').should == date_string
52
76
  end
53
77
 
54
78
  context "with plugin parser" do
@@ -95,7 +119,7 @@ describe ValidatesTimeliness, 'Mongoid' do
95
119
  r = Article.create!
96
120
  r.publish_date = '2010-01-01'
97
121
  r.reload
98
- r._timeliness_raw_value_for(:publish_date).should be_nil
122
+ r._timeliness_raw_value_for('publish_date').should be_nil
99
123
  end
100
124
  end
101
125
 
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
18
18
 
19
- s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.4"])
19
+ s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.5"])
20
20
  end
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 9
10
- version: 3.0.9
9
+ - 10
10
+ version: 3.0.10
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-03-26 00:00:00 +11:00
18
+ date: 2012-03-29 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,12 +24,12 @@ dependencies:
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- hash: 27
27
+ hash: 25
28
28
  segments:
29
29
  - 0
30
30
  - 3
31
- - 4
32
- version: 0.3.4
31
+ - 5
32
+ version: 0.3.5
33
33
  name: timeliness
34
34
  prerelease: false
35
35
  type: :runtime