validates_timeliness 3.0.2 → 3.0.3

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.3 [2010-12-11]
2
+ * Fix validation of values which don't respond to to_date or to_time (renatoelias)
3
+
1
4
  = 3.0.2 [2010-12-04]
2
5
  * Fix AR multiparameter extension for Date columns
3
6
  * Update to Timeliness 0.3.2 for zone abbreviation and offset support
@@ -2,7 +2,7 @@ module ValidatesTimeliness
2
2
  module Conversion
3
3
 
4
4
  def type_cast_value(value, type)
5
- return nil if value.nil?
5
+ return nil if value.nil? || !value.respond_to?(:to_time)
6
6
 
7
7
  value = value.in_time_zone if value.acts_like?(:time) && @timezone_aware
8
8
  value = case type
@@ -72,9 +72,8 @@ module ValidatesTimeliness
72
72
  end
73
73
 
74
74
  def attribute_raw_value(record, attr_name)
75
- if record.respond_to?(:_timeliness_raw_value_for)
75
+ record.respond_to?(:_timeliness_raw_value_for) &&
76
76
  record._timeliness_raw_value_for(attr_name)
77
- end
78
77
  end
79
78
 
80
79
  def timezone_aware?(record, attr_name)
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '3.0.2'
2
+ VERSION = '3.0.3'
3
3
  end
@@ -22,6 +22,10 @@ describe ValidatesTimeliness::Conversion do
22
22
  it "should return date part of datetime value" do
23
23
  type_cast_value(DateTime.new(2010, 1, 1, 0, 0, 0), :date).should == Date.new(2010, 1, 1)
24
24
  end
25
+
26
+ it 'should return nil for invalid value types' do
27
+ type_cast_value(12, :date).should == nil
28
+ end
25
29
  end
26
30
 
27
31
  describe "for time type" do
@@ -40,6 +44,10 @@ describe ValidatesTimeliness::Conversion do
40
44
  it "should return dummy date with time part for datetime value" do
41
45
  type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :time).should == Time.utc(2000, 1, 1, 12, 34, 56)
42
46
  end
47
+
48
+ it 'should return nil for invalid value types' do
49
+ type_cast_value(12, :time).should == nil
50
+ end
43
51
  end
44
52
 
45
53
  describe "for datetime type" do
@@ -63,6 +71,10 @@ describe ValidatesTimeliness::Conversion do
63
71
  result.should == Time.zone.local(2010, 1, 1, 23, 34, 56)
64
72
  result.zone.should == 'EST'
65
73
  end
74
+
75
+ it 'should return nil for invalid value types' do
76
+ type_cast_value(12, :datetime).should == nil
77
+ end
66
78
  end
67
79
 
68
80
  describe "ignore_usec option" do
@@ -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.2"
5
+ s.version = "3.0.3"
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-12-04}
9
+ s.date = %q{2010-12-11}
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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 2
10
- version: 3.0.2
9
+ - 3
10
+ version: 3.0.3
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-12-04 00:00:00 +11:00
18
+ date: 2010-12-11 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency