rails_validations 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddd6882125ca697433e2c84a1abe00d27915a047
4
- data.tar.gz: c5989625d5445cc3c945dacca0508af06326bc34
3
+ metadata.gz: a12b5368bba78e7aab87a70d991dba1dd11c8547
4
+ data.tar.gz: 95efbaabfe4fb4621617a36917f369cfdc54340e
5
5
  SHA512:
6
- metadata.gz: ec30b335a30fe9d5edcb557305aba2801d7311482ae6524beed630a6c4b0a26ee445211cf911b217663d316807c73fe537468a27b7dc54e14433106e1d763ffd
7
- data.tar.gz: 28d39fdf01a7018dd1497b02188016bb350fb85655c1c773695b6d673f016f5f7098b749970a5c81e2b37ccd49ddf9685f31c82a5da0ff8c901f47dbe12fe6fa
6
+ metadata.gz: f489d4415e90345fb2c52b5258eb8caa31a12a07198fb760b5b1d4d494d3280dd749393b49940d7429ff7e4d734c1ac8c6db96f097791f139d01ea577a817c87
7
+ data.tar.gz: 49dc62c80cdae17e1721ee82616765abe7314707bcc81d3b1124be526ee5ef39e3cb9ffb4608e8cc4eb51806541e7a13a95fcf2419e730b958e8e2eadcffaa3e
data/README.markdown CHANGED
@@ -96,6 +96,10 @@ Currently implemented countries:
96
96
 
97
97
  ChangeLog
98
98
  =========
99
+ Version 1.1.4, 2014-12-28
100
+ -------------------------
101
+ - Bugfix for Date validator when comparing to other columns that are a String.
102
+
99
103
 
100
104
  Version 1.1.3, 2014-12-03
101
105
  -------------------------
@@ -27,24 +27,25 @@ class DateValidator < ActiveModel::EachValidator
27
27
  }.freeze
28
28
 
29
29
 
30
- def validate_each record, attribute, raw_value
30
+ def value_to_date raw_value
31
31
  # TODO: Do we need to do anything with timezones? Figure it out (rails has
32
32
  # ActiveSupport::TimeWithZone)...
33
- value = if raw_value.is_a? Fixnum
34
- time.at(raw_value).to_date
35
- elsif raw_value.respond_to? :to_date
36
- begin
37
- raw_value.to_date
38
- rescue ArgumentError
39
- false
40
- end
41
- else
42
- false
43
- end
33
+ if raw_value.is_a? Fixnum
34
+ time.at(raw_value).to_date
35
+ elsif raw_value.respond_to? :to_date
36
+ begin
37
+ raw_value.to_date
38
+ rescue ArgumentError
39
+ false
40
+ end
41
+ else
42
+ false
43
+ end
44
+ end
45
+
44
46
 
45
- #elsif raw_value.is_a?(Symbol) || raw_value.is_a?(String)
46
- # # Assume another (date) attribute
47
- # record.send(raw_value).to_date
47
+ def validate_each record, attribute, raw_value
48
+ value = value_to_date raw_value
48
49
 
49
50
  unless value
50
51
  record.errors.add attribute, I18n.t('rails_validations.date.invalid')
@@ -59,7 +60,7 @@ class DateValidator < ActiveModel::EachValidator
59
60
  raw_option_value.call record
60
61
  end
61
62
  elsif raw_option_value.is_a? Symbol
62
- record.send raw_option_value
63
+ value_to_date record.send(raw_option_value)
63
64
  elsif raw_option_value.is_a? Fixnum
64
65
  time.at(raw_option_value).to_date
65
66
  elsif raw_option_value.respond_to? :to_date
@@ -68,4 +68,12 @@ describe ValidationsSpecHelper::Date do
68
68
  expect(model('Yesterday, a fish nibbled my toe.')).to_not be_valid
69
69
  end
70
70
  end
71
+
72
+
73
+ it 'works when comparing to another column' do
74
+ with_validation 'date: { after: :v2 }' do
75
+ expect(model(Date.today, Date.today - 2.days)).to be_valid
76
+ expect(model(Date.today.to_s, (Date.today - 2.days).to_s)).to be_valid
77
+ end
78
+ end
71
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Tournoij
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack