better_date_picker 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2616de8938c241c1a0df6886e80243d1b27ef78d
4
- data.tar.gz: 1abbe7e488e811510d0147776f725399e6a0fe3d
3
+ metadata.gz: 9acbffc89e0ec233935aabd7da69f060788bf4f1
4
+ data.tar.gz: c5a6e130d0472ada567cb2908cd12038a78eaadd
5
5
  SHA512:
6
- metadata.gz: b2983ee5573052224ff64125de9ca8f4b07c0a469617374541b45eb4f2a4a98989381cd4ba812caec98992d4ab471cc9bfb79b26219acb99135f79623e2f8d7a
7
- data.tar.gz: ddbc00fef08e5bcd8be3752bfb9c41eaedf97e4fcce8888bc576c5220a90f365d0356ae96546ff4c9e030e2ee29121ad48e98a7a2c59a4fae2fd59e382864932
6
+ metadata.gz: d6d55c00a79280e81947ddb94e2230a574aefdbfc6b0e99135e3a6ea13235eb534c03068e6d541d8dc07b2e04c0037b9d6df39e4ddeacbd89dfa3d73410f7611
7
+ data.tar.gz: c0374ceeae54f154638fc1b59059098a069228637c4a7b8f9f7d44eddaf5311e37e6f0a26d1ed6ba45a7f961cba0052f6c0b48e1086d3c3de120fef8079b34c9
@@ -17,6 +17,10 @@ module BetterDatePicker
17
17
  self.better_date_fields ||= []
18
18
  self.better_date_defaults ||= {}
19
19
 
20
+ if self.better_date_fields.empty?
21
+ after_validation :propagate_better_date_errors
22
+ end
23
+
20
24
  define_method "#{field}=" do |date_val|
21
25
  #we don't want to clobber the ivar if we're setting via the string
22
26
  val_to_set = date_val.nil? ? nil : date_val.strftime(self.class.better_date_format)
@@ -56,5 +60,16 @@ module BetterDatePicker
56
60
  "%m/%d/%Y"
57
61
  end
58
62
  end
63
+
64
+ protected
65
+ def propagate_better_date_errors
66
+ if self.class.better_date_fields && !self.class.better_date_fields.empty?
67
+ self.class.better_date_fields.each do |field|
68
+ if self.errors[field].present?
69
+ self.errors["#{field}_date"] = self.errors[field]
70
+ end
71
+ end
72
+ end
73
+ end
59
74
  end
60
75
  end
@@ -1,3 +1,3 @@
1
1
  module BetterDatePicker
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -9,6 +9,9 @@ describe BetterDatePicker::Model do
9
9
 
10
10
  attr_accessor :built_at
11
11
 
12
+ validates :built_at,
13
+ presence: true
14
+
12
15
  better_date_picker :built_at
13
16
  end
14
17
 
@@ -45,4 +48,10 @@ describe BetterDatePicker::Model do
45
48
  widget.built_at = nil
46
49
  expect(widget.built_at_date).to be_nil
47
50
  end
51
+
52
+ it 'propagates errors to the stringified version when validated' do
53
+ widget = Widget.new
54
+ expect(widget).to_not be_valid
55
+ expect(widget.errors[:built_at_date]).to_not be_blank
56
+ end
48
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_date_picker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel