valuedate 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/valuedate.rb +3 -3
- data/test/test_valuedate.rb +2 -6
- data/test.watchr +1 -0
- data/valuedate.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/valuedate.rb
CHANGED
@@ -51,7 +51,7 @@ class Valuedate
|
|
51
51
|
valid? do |value|
|
52
52
|
value ||= {}
|
53
53
|
schema.all? do |(key, validator)|
|
54
|
-
validator.call(value[key]) || collect_errors!(validator,
|
54
|
+
validator.call(value[key]) || collect_errors!(validator, key)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -74,10 +74,10 @@ class Valuedate
|
|
74
74
|
self
|
75
75
|
end
|
76
76
|
|
77
|
-
def collect_errors!(validator,
|
77
|
+
def collect_errors!(validator, key=nil)
|
78
78
|
case validator
|
79
79
|
when Valuedate
|
80
|
-
@errors.concat(validator.errors.map { |error| error.options
|
80
|
+
@errors.concat(validator.errors.map { |error| error.options[:key] ||= key; error })
|
81
81
|
end
|
82
82
|
false
|
83
83
|
end
|
data/test/test_valuedate.rb
CHANGED
@@ -196,6 +196,7 @@ context "Valuedate" do
|
|
196
196
|
asserts("invalid array size") { !v([1,2]) { value.not { |value| value.size == 2 } } }
|
197
197
|
end
|
198
198
|
|
199
|
+
# TODO refactor!
|
199
200
|
context "errors" do
|
200
201
|
setup do
|
201
202
|
Valuedate.schema {}
|
@@ -220,12 +221,7 @@ context "Valuedate" do
|
|
220
221
|
end
|
221
222
|
|
222
223
|
asserts("fails") { !topic.validate({}) }
|
223
|
-
asserts_validation_error(:key => :
|
224
|
-
asserts_validation_error(:key => :key1, :matcher => :is_a) { topic.validate!(:key1 => 23) }
|
225
|
-
asserts_validation_error(:key => :key1, :matcher => :equals) { topic.validate!(:key1 => "value") }
|
226
|
-
asserts_validation_error(:key => :key2, :matcher => :is_a) { topic.validate!(:key1 => "key") }
|
227
|
-
asserts_validation_error(:key => :key2, :matcher => :is_a) { topic.validate!(:key1 => "key", :key2 => {}) }
|
228
|
-
asserts_validation_error(:key => :key2, :matcher => :is_a) { topic.validate!(:key1 => "key", :key2 => {:key3 => 0.0}) }
|
224
|
+
asserts_validation_error(:key => :key3, :matcher => :is_a) { topic.validate!(:key1 => "key", :key2 => {:key3 => 0.0}) }
|
229
225
|
asserts("passes") { topic.validate(:key1 => "key", :key2 => {:key3 => 23}) }
|
230
226
|
end
|
231
227
|
end
|
data/test.watchr
CHANGED
data/valuedate.gemspec
CHANGED