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 +4 -4
- data/lib/better_date_picker/model.rb +15 -0
- data/lib/better_date_picker/version.rb +1 -1
- data/spec/better_date_picker/model_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9acbffc89e0ec233935aabd7da69f060788bf4f1
|
4
|
+
data.tar.gz: c5a6e130d0472ada567cb2908cd12038a78eaadd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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.
|
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-
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|