dry-validation 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -6
  4. data/CHANGELOG.md +58 -0
  5. data/Gemfile +3 -3
  6. data/benchmarks/benchmark_form_invalid.rb +64 -0
  7. data/benchmarks/benchmark_form_valid.rb +64 -0
  8. data/benchmarks/profile_schema_call_invalid.rb +20 -0
  9. data/benchmarks/profile_schema_call_valid.rb +20 -0
  10. data/benchmarks/profile_schema_definition.rb +14 -0
  11. data/benchmarks/profile_schema_messages_invalid.rb +20 -0
  12. data/benchmarks/suite.rb +5 -0
  13. data/config/errors.yml +12 -5
  14. data/dry-validation.gemspec +2 -2
  15. data/examples/basic.rb +2 -2
  16. data/examples/form.rb +2 -2
  17. data/examples/json.rb +2 -2
  18. data/examples/nested.rb +6 -6
  19. data/lib/dry/validation.rb +22 -3
  20. data/lib/dry/validation/deprecations.rb +23 -0
  21. data/lib/dry/validation/error_compiler.rb +31 -11
  22. data/lib/dry/validation/error_compiler/input.rb +44 -57
  23. data/lib/dry/validation/hint_compiler.rb +15 -7
  24. data/lib/dry/validation/input_processor_compiler.rb +13 -6
  25. data/lib/dry/validation/input_processor_compiler/form.rb +2 -0
  26. data/lib/dry/validation/input_processor_compiler/sanitizer.rb +1 -1
  27. data/lib/dry/validation/messages/abstract.rb +9 -1
  28. data/lib/dry/validation/predicate_registry.rb +101 -0
  29. data/lib/dry/validation/result.rb +8 -1
  30. data/lib/dry/validation/schema.rb +110 -44
  31. data/lib/dry/validation/schema/check.rb +4 -2
  32. data/lib/dry/validation/schema/deprecated.rb +31 -0
  33. data/lib/dry/validation/schema/dsl.rb +18 -11
  34. data/lib/dry/validation/schema/form.rb +1 -0
  35. data/lib/dry/validation/schema/json.rb +1 -0
  36. data/lib/dry/validation/schema/key.rb +23 -10
  37. data/lib/dry/validation/schema/rule.rb +81 -20
  38. data/lib/dry/validation/schema/value.rb +110 -25
  39. data/lib/dry/validation/version.rb +1 -1
  40. data/spec/fixtures/locales/en.yml +1 -0
  41. data/spec/fixtures/locales/pl.yml +1 -1
  42. data/spec/integration/custom_error_messages_spec.rb +2 -2
  43. data/spec/integration/custom_predicates_spec.rb +98 -15
  44. data/spec/integration/error_compiler_spec.rb +111 -96
  45. data/spec/integration/form/predicates/array_spec.rb +243 -0
  46. data/spec/integration/form/predicates/empty_spec.rb +263 -0
  47. data/spec/integration/form/predicates/eql_spec.rb +327 -0
  48. data/spec/integration/form/predicates/even_spec.rb +455 -0
  49. data/spec/integration/form/predicates/excluded_from_spec.rb +455 -0
  50. data/spec/integration/form/predicates/excludes_spec.rb +391 -0
  51. data/spec/integration/form/predicates/false_spec.rb +455 -0
  52. data/spec/integration/form/predicates/filled_spec.rb +467 -0
  53. data/spec/integration/form/predicates/format_spec.rb +454 -0
  54. data/spec/integration/form/predicates/gt_spec.rb +519 -0
  55. data/spec/integration/form/predicates/gteq_spec.rb +519 -0
  56. data/spec/integration/form/predicates/included_in_spec.rb +455 -0
  57. data/spec/integration/form/predicates/includes_spec.rb +391 -0
  58. data/spec/integration/form/predicates/key_spec.rb +75 -0
  59. data/spec/integration/form/predicates/lt_spec.rb +519 -0
  60. data/spec/integration/form/predicates/lteq_spec.rb +519 -0
  61. data/spec/integration/form/predicates/max_size_spec.rb +391 -0
  62. data/spec/integration/form/predicates/min_size_spec.rb +391 -0
  63. data/spec/integration/form/predicates/none_spec.rb +265 -0
  64. data/spec/integration/form/predicates/not_eql_spec.rb +327 -0
  65. data/spec/integration/form/predicates/odd_spec.rb +455 -0
  66. data/spec/integration/form/predicates/size/fixed_spec.rb +399 -0
  67. data/spec/integration/form/predicates/size/range_spec.rb +398 -0
  68. data/spec/integration/form/predicates/true_spec.rb +455 -0
  69. data/spec/integration/form/predicates/type_spec.rb +391 -0
  70. data/spec/integration/hints_spec.rb +90 -4
  71. data/spec/integration/injecting_rules_spec.rb +2 -2
  72. data/spec/integration/localized_error_messages_spec.rb +2 -2
  73. data/spec/integration/messages/i18n_spec.rb +3 -3
  74. data/spec/integration/optional_keys_spec.rb +3 -3
  75. data/spec/integration/schema/array_schema_spec.rb +49 -13
  76. data/spec/integration/schema/check_rules_spec.rb +6 -6
  77. data/spec/integration/schema/check_with_nested_el_spec.rb +3 -3
  78. data/spec/integration/schema/check_with_nth_el_spec.rb +1 -1
  79. data/spec/integration/schema/each_with_set_spec.rb +3 -3
  80. data/spec/integration/schema/extending_dsl_spec.rb +27 -0
  81. data/spec/integration/schema/form/explicit_types_spec.rb +182 -0
  82. data/spec/integration/schema/form_spec.rb +90 -18
  83. data/spec/integration/schema/hash_schema_spec.rb +47 -0
  84. data/spec/integration/schema/inheriting_schema_spec.rb +4 -4
  85. data/spec/integration/schema/input_processor_spec.rb +8 -8
  86. data/spec/integration/schema/json/explicit_types_spec.rb +157 -0
  87. data/spec/integration/schema/json_spec.rb +18 -18
  88. data/spec/integration/schema/macros/confirmation_spec.rb +1 -1
  89. data/spec/integration/schema/macros/each_spec.rb +177 -43
  90. data/spec/integration/schema/macros/{required_spec.rb → filled_spec.rb} +34 -6
  91. data/spec/integration/schema/macros/input_spec.rb +21 -0
  92. data/spec/integration/schema/macros/maybe_spec.rb +39 -2
  93. data/spec/integration/schema/macros/value_spec.rb +105 -0
  94. data/spec/integration/schema/macros/when_spec.rb +28 -8
  95. data/spec/integration/schema/nested_values_spec.rb +11 -8
  96. data/spec/integration/schema/not_spec.rb +2 -2
  97. data/spec/integration/schema/numbers_spec.rb +1 -1
  98. data/spec/integration/schema/option_with_default_spec.rb +1 -1
  99. data/spec/integration/schema/predicate_verification_spec.rb +9 -0
  100. data/spec/integration/schema/predicates/array_spec.rb +295 -0
  101. data/spec/integration/schema/predicates/custom_spec.rb +103 -0
  102. data/spec/integration/schema/predicates/empty_spec.rb +263 -0
  103. data/spec/integration/schema/predicates/eql_spec.rb +327 -0
  104. data/spec/integration/schema/predicates/even_spec.rb +455 -0
  105. data/spec/integration/schema/predicates/excluded_from_spec.rb +455 -0
  106. data/spec/integration/schema/predicates/excludes_spec.rb +391 -0
  107. data/spec/integration/schema/predicates/filled_spec.rb +467 -0
  108. data/spec/integration/schema/predicates/format_spec.rb +455 -0
  109. data/spec/integration/schema/predicates/gt_spec.rb +519 -0
  110. data/spec/integration/schema/predicates/gteq_spec.rb +519 -0
  111. data/spec/integration/schema/predicates/hash_spec.rb +69 -0
  112. data/spec/integration/schema/predicates/included_in_spec.rb +455 -0
  113. data/spec/integration/schema/predicates/includes_spec.rb +391 -0
  114. data/spec/integration/schema/predicates/key_spec.rb +88 -0
  115. data/spec/integration/schema/predicates/lt_spec.rb +520 -0
  116. data/spec/integration/schema/predicates/lteq_spec.rb +519 -0
  117. data/spec/integration/schema/predicates/max_size_spec.rb +391 -0
  118. data/spec/integration/schema/predicates/min_size_spec.rb +391 -0
  119. data/spec/integration/schema/predicates/none_spec.rb +265 -0
  120. data/spec/integration/schema/predicates/not_eql_spec.rb +391 -0
  121. data/spec/integration/schema/predicates/odd_spec.rb +455 -0
  122. data/spec/integration/schema/predicates/size/fixed_spec.rb +401 -0
  123. data/spec/integration/schema/predicates/size/range_spec.rb +399 -0
  124. data/spec/integration/schema/predicates/type_spec.rb +391 -0
  125. data/spec/integration/schema/reusing_schema_spec.rb +4 -4
  126. data/spec/integration/schema/using_types_spec.rb +24 -6
  127. data/spec/integration/schema/xor_spec.rb +2 -2
  128. data/spec/integration/schema_builders_spec.rb +15 -0
  129. data/spec/integration/schema_spec.rb +37 -12
  130. data/spec/shared/predicate_helper.rb +13 -0
  131. data/spec/spec_helper.rb +10 -0
  132. data/spec/support/matchers.rb +38 -0
  133. data/spec/support/predicates_integration.rb +7 -0
  134. data/spec/unit/hint_compiler_spec.rb +10 -8
  135. data/spec/unit/input_processor_compiler/form_spec.rb +45 -43
  136. data/spec/unit/input_processor_compiler/json_spec.rb +37 -35
  137. data/spec/unit/predicate_registry_spec.rb +34 -0
  138. data/spec/unit/schema/key_spec.rb +12 -14
  139. data/spec/unit/schema/rule_spec.rb +4 -2
  140. data/spec/unit/schema/value_spec.rb +38 -121
  141. metadata +150 -16
  142. data/lib/dry/validation/schema/attr.rb +0 -15
  143. data/spec/integration/attr_spec.rb +0 -122
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-06 00:00:00.000000000 Z
12
+ date: 2016-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -85,40 +85,40 @@ dependencies:
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0.2'
88
+ version: '0.3'
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
- version: 0.2.2
91
+ version: 0.3.0
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: '0.2'
98
+ version: '0.3'
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: 0.2.2
101
+ version: 0.3.0
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: dry-types
104
104
  requirement: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '0.6'
108
+ version: '0.8'
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: 0.6.0
111
+ version: 0.8.0
112
112
  type: :runtime
113
113
  prerelease: false
114
114
  version_requirements: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0.6'
118
+ version: '0.8'
119
119
  - - ">="
120
120
  - !ruby/object:Gem::Version
121
- version: 0.6.0
121
+ version: 0.8.0
122
122
  - !ruby/object:Gem::Dependency
123
123
  name: bundler
124
124
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +165,8 @@ description:
165
165
  email:
166
166
  - andyholland1991@aol.com
167
167
  - piotr.solnica@gmail.com
168
- executables: []
168
+ executables:
169
+ - console
169
170
  extensions: []
170
171
  extra_rdoc_files: []
171
172
  files:
@@ -178,6 +179,14 @@ files:
178
179
  - LICENSE
179
180
  - README.md
180
181
  - Rakefile
182
+ - benchmarks/benchmark_form_invalid.rb
183
+ - benchmarks/benchmark_form_valid.rb
184
+ - benchmarks/profile_schema_call_invalid.rb
185
+ - benchmarks/profile_schema_call_valid.rb
186
+ - benchmarks/profile_schema_definition.rb
187
+ - benchmarks/profile_schema_messages_invalid.rb
188
+ - benchmarks/suite.rb
189
+ - bin/console
181
190
  - config/errors.yml
182
191
  - dry-validation.gemspec
183
192
  - examples/basic.rb
@@ -188,6 +197,7 @@ files:
188
197
  - examples/rule_ast.rb
189
198
  - lib/dry-validation.rb
190
199
  - lib/dry/validation.rb
200
+ - lib/dry/validation/deprecations.rb
191
201
  - lib/dry/validation/error.rb
192
202
  - lib/dry/validation/error_compiler.rb
193
203
  - lib/dry/validation/error_compiler/input.rb
@@ -201,10 +211,11 @@ files:
201
211
  - lib/dry/validation/messages/i18n.rb
202
212
  - lib/dry/validation/messages/namespaced.rb
203
213
  - lib/dry/validation/messages/yaml.rb
214
+ - lib/dry/validation/predicate_registry.rb
204
215
  - lib/dry/validation/result.rb
205
216
  - lib/dry/validation/schema.rb
206
- - lib/dry/validation/schema/attr.rb
207
217
  - lib/dry/validation/schema/check.rb
218
+ - lib/dry/validation/schema/deprecated.rb
208
219
  - lib/dry/validation/schema/dsl.rb
209
220
  - lib/dry/validation/schema/form.rb
210
221
  - lib/dry/validation/schema/json.rb
@@ -213,12 +224,37 @@ files:
213
224
  - lib/dry/validation/schema/value.rb
214
225
  - lib/dry/validation/schema_compiler.rb
215
226
  - lib/dry/validation/version.rb
227
+ - log/.gitkeep
216
228
  - spec/fixtures/locales/en.yml
217
229
  - spec/fixtures/locales/pl.yml
218
- - spec/integration/attr_spec.rb
219
230
  - spec/integration/custom_error_messages_spec.rb
220
231
  - spec/integration/custom_predicates_spec.rb
221
232
  - spec/integration/error_compiler_spec.rb
233
+ - spec/integration/form/predicates/array_spec.rb
234
+ - spec/integration/form/predicates/empty_spec.rb
235
+ - spec/integration/form/predicates/eql_spec.rb
236
+ - spec/integration/form/predicates/even_spec.rb
237
+ - spec/integration/form/predicates/excluded_from_spec.rb
238
+ - spec/integration/form/predicates/excludes_spec.rb
239
+ - spec/integration/form/predicates/false_spec.rb
240
+ - spec/integration/form/predicates/filled_spec.rb
241
+ - spec/integration/form/predicates/format_spec.rb
242
+ - spec/integration/form/predicates/gt_spec.rb
243
+ - spec/integration/form/predicates/gteq_spec.rb
244
+ - spec/integration/form/predicates/included_in_spec.rb
245
+ - spec/integration/form/predicates/includes_spec.rb
246
+ - spec/integration/form/predicates/key_spec.rb
247
+ - spec/integration/form/predicates/lt_spec.rb
248
+ - spec/integration/form/predicates/lteq_spec.rb
249
+ - spec/integration/form/predicates/max_size_spec.rb
250
+ - spec/integration/form/predicates/min_size_spec.rb
251
+ - spec/integration/form/predicates/none_spec.rb
252
+ - spec/integration/form/predicates/not_eql_spec.rb
253
+ - spec/integration/form/predicates/odd_spec.rb
254
+ - spec/integration/form/predicates/size/fixed_spec.rb
255
+ - spec/integration/form/predicates/size/range_spec.rb
256
+ - spec/integration/form/predicates/true_spec.rb
257
+ - spec/integration/form/predicates/type_spec.rb
222
258
  - spec/integration/hints_spec.rb
223
259
  - spec/integration/injecting_rules_spec.rb
224
260
  - spec/integration/localized_error_messages_spec.rb
@@ -229,30 +265,67 @@ files:
229
265
  - spec/integration/schema/check_with_nested_el_spec.rb
230
266
  - spec/integration/schema/check_with_nth_el_spec.rb
231
267
  - spec/integration/schema/each_with_set_spec.rb
268
+ - spec/integration/schema/extending_dsl_spec.rb
269
+ - spec/integration/schema/form/explicit_types_spec.rb
232
270
  - spec/integration/schema/form_spec.rb
271
+ - spec/integration/schema/hash_schema_spec.rb
233
272
  - spec/integration/schema/inheriting_schema_spec.rb
234
273
  - spec/integration/schema/input_processor_spec.rb
274
+ - spec/integration/schema/json/explicit_types_spec.rb
235
275
  - spec/integration/schema/json_spec.rb
236
276
  - spec/integration/schema/macros/confirmation_spec.rb
237
277
  - spec/integration/schema/macros/each_spec.rb
278
+ - spec/integration/schema/macros/filled_spec.rb
279
+ - spec/integration/schema/macros/input_spec.rb
238
280
  - spec/integration/schema/macros/maybe_spec.rb
239
- - spec/integration/schema/macros/required_spec.rb
281
+ - spec/integration/schema/macros/value_spec.rb
240
282
  - spec/integration/schema/macros/when_spec.rb
241
283
  - spec/integration/schema/nested_values_spec.rb
242
284
  - spec/integration/schema/not_spec.rb
243
285
  - spec/integration/schema/numbers_spec.rb
244
286
  - spec/integration/schema/option_with_default_spec.rb
287
+ - spec/integration/schema/predicate_verification_spec.rb
288
+ - spec/integration/schema/predicates/array_spec.rb
289
+ - spec/integration/schema/predicates/custom_spec.rb
290
+ - spec/integration/schema/predicates/empty_spec.rb
291
+ - spec/integration/schema/predicates/eql_spec.rb
292
+ - spec/integration/schema/predicates/even_spec.rb
293
+ - spec/integration/schema/predicates/excluded_from_spec.rb
294
+ - spec/integration/schema/predicates/excludes_spec.rb
295
+ - spec/integration/schema/predicates/filled_spec.rb
296
+ - spec/integration/schema/predicates/format_spec.rb
297
+ - spec/integration/schema/predicates/gt_spec.rb
298
+ - spec/integration/schema/predicates/gteq_spec.rb
299
+ - spec/integration/schema/predicates/hash_spec.rb
300
+ - spec/integration/schema/predicates/included_in_spec.rb
301
+ - spec/integration/schema/predicates/includes_spec.rb
302
+ - spec/integration/schema/predicates/key_spec.rb
303
+ - spec/integration/schema/predicates/lt_spec.rb
304
+ - spec/integration/schema/predicates/lteq_spec.rb
305
+ - spec/integration/schema/predicates/max_size_spec.rb
306
+ - spec/integration/schema/predicates/min_size_spec.rb
307
+ - spec/integration/schema/predicates/none_spec.rb
308
+ - spec/integration/schema/predicates/not_eql_spec.rb
309
+ - spec/integration/schema/predicates/odd_spec.rb
310
+ - spec/integration/schema/predicates/size/fixed_spec.rb
311
+ - spec/integration/schema/predicates/size/range_spec.rb
312
+ - spec/integration/schema/predicates/type_spec.rb
245
313
  - spec/integration/schema/reusing_schema_spec.rb
246
314
  - spec/integration/schema/using_types_spec.rb
247
315
  - spec/integration/schema/xor_spec.rb
316
+ - spec/integration/schema_builders_spec.rb
248
317
  - spec/integration/schema_spec.rb
318
+ - spec/shared/predicate_helper.rb
249
319
  - spec/shared/rule_compiler.rb
250
320
  - spec/spec_helper.rb
251
321
  - spec/support/define_struct.rb
322
+ - spec/support/matchers.rb
323
+ - spec/support/predicates_integration.rb
252
324
  - spec/unit/error_compiler_spec.rb
253
325
  - spec/unit/hint_compiler_spec.rb
254
326
  - spec/unit/input_processor_compiler/form_spec.rb
255
327
  - spec/unit/input_processor_compiler/json_spec.rb
328
+ - spec/unit/predicate_registry_spec.rb
256
329
  - spec/unit/schema/key_spec.rb
257
330
  - spec/unit/schema/rule_spec.rb
258
331
  - spec/unit/schema/value_spec.rb
@@ -284,10 +357,34 @@ summary: A simple validation library
284
357
  test_files:
285
358
  - spec/fixtures/locales/en.yml
286
359
  - spec/fixtures/locales/pl.yml
287
- - spec/integration/attr_spec.rb
288
360
  - spec/integration/custom_error_messages_spec.rb
289
361
  - spec/integration/custom_predicates_spec.rb
290
362
  - spec/integration/error_compiler_spec.rb
363
+ - spec/integration/form/predicates/array_spec.rb
364
+ - spec/integration/form/predicates/empty_spec.rb
365
+ - spec/integration/form/predicates/eql_spec.rb
366
+ - spec/integration/form/predicates/even_spec.rb
367
+ - spec/integration/form/predicates/excluded_from_spec.rb
368
+ - spec/integration/form/predicates/excludes_spec.rb
369
+ - spec/integration/form/predicates/false_spec.rb
370
+ - spec/integration/form/predicates/filled_spec.rb
371
+ - spec/integration/form/predicates/format_spec.rb
372
+ - spec/integration/form/predicates/gt_spec.rb
373
+ - spec/integration/form/predicates/gteq_spec.rb
374
+ - spec/integration/form/predicates/included_in_spec.rb
375
+ - spec/integration/form/predicates/includes_spec.rb
376
+ - spec/integration/form/predicates/key_spec.rb
377
+ - spec/integration/form/predicates/lt_spec.rb
378
+ - spec/integration/form/predicates/lteq_spec.rb
379
+ - spec/integration/form/predicates/max_size_spec.rb
380
+ - spec/integration/form/predicates/min_size_spec.rb
381
+ - spec/integration/form/predicates/none_spec.rb
382
+ - spec/integration/form/predicates/not_eql_spec.rb
383
+ - spec/integration/form/predicates/odd_spec.rb
384
+ - spec/integration/form/predicates/size/fixed_spec.rb
385
+ - spec/integration/form/predicates/size/range_spec.rb
386
+ - spec/integration/form/predicates/true_spec.rb
387
+ - spec/integration/form/predicates/type_spec.rb
291
388
  - spec/integration/hints_spec.rb
292
389
  - spec/integration/injecting_rules_spec.rb
293
390
  - spec/integration/localized_error_messages_spec.rb
@@ -298,30 +395,67 @@ test_files:
298
395
  - spec/integration/schema/check_with_nested_el_spec.rb
299
396
  - spec/integration/schema/check_with_nth_el_spec.rb
300
397
  - spec/integration/schema/each_with_set_spec.rb
398
+ - spec/integration/schema/extending_dsl_spec.rb
399
+ - spec/integration/schema/form/explicit_types_spec.rb
301
400
  - spec/integration/schema/form_spec.rb
401
+ - spec/integration/schema/hash_schema_spec.rb
302
402
  - spec/integration/schema/inheriting_schema_spec.rb
303
403
  - spec/integration/schema/input_processor_spec.rb
404
+ - spec/integration/schema/json/explicit_types_spec.rb
304
405
  - spec/integration/schema/json_spec.rb
305
406
  - spec/integration/schema/macros/confirmation_spec.rb
306
407
  - spec/integration/schema/macros/each_spec.rb
408
+ - spec/integration/schema/macros/filled_spec.rb
409
+ - spec/integration/schema/macros/input_spec.rb
307
410
  - spec/integration/schema/macros/maybe_spec.rb
308
- - spec/integration/schema/macros/required_spec.rb
411
+ - spec/integration/schema/macros/value_spec.rb
309
412
  - spec/integration/schema/macros/when_spec.rb
310
413
  - spec/integration/schema/nested_values_spec.rb
311
414
  - spec/integration/schema/not_spec.rb
312
415
  - spec/integration/schema/numbers_spec.rb
313
416
  - spec/integration/schema/option_with_default_spec.rb
417
+ - spec/integration/schema/predicate_verification_spec.rb
418
+ - spec/integration/schema/predicates/array_spec.rb
419
+ - spec/integration/schema/predicates/custom_spec.rb
420
+ - spec/integration/schema/predicates/empty_spec.rb
421
+ - spec/integration/schema/predicates/eql_spec.rb
422
+ - spec/integration/schema/predicates/even_spec.rb
423
+ - spec/integration/schema/predicates/excluded_from_spec.rb
424
+ - spec/integration/schema/predicates/excludes_spec.rb
425
+ - spec/integration/schema/predicates/filled_spec.rb
426
+ - spec/integration/schema/predicates/format_spec.rb
427
+ - spec/integration/schema/predicates/gt_spec.rb
428
+ - spec/integration/schema/predicates/gteq_spec.rb
429
+ - spec/integration/schema/predicates/hash_spec.rb
430
+ - spec/integration/schema/predicates/included_in_spec.rb
431
+ - spec/integration/schema/predicates/includes_spec.rb
432
+ - spec/integration/schema/predicates/key_spec.rb
433
+ - spec/integration/schema/predicates/lt_spec.rb
434
+ - spec/integration/schema/predicates/lteq_spec.rb
435
+ - spec/integration/schema/predicates/max_size_spec.rb
436
+ - spec/integration/schema/predicates/min_size_spec.rb
437
+ - spec/integration/schema/predicates/none_spec.rb
438
+ - spec/integration/schema/predicates/not_eql_spec.rb
439
+ - spec/integration/schema/predicates/odd_spec.rb
440
+ - spec/integration/schema/predicates/size/fixed_spec.rb
441
+ - spec/integration/schema/predicates/size/range_spec.rb
442
+ - spec/integration/schema/predicates/type_spec.rb
314
443
  - spec/integration/schema/reusing_schema_spec.rb
315
444
  - spec/integration/schema/using_types_spec.rb
316
445
  - spec/integration/schema/xor_spec.rb
446
+ - spec/integration/schema_builders_spec.rb
317
447
  - spec/integration/schema_spec.rb
448
+ - spec/shared/predicate_helper.rb
318
449
  - spec/shared/rule_compiler.rb
319
450
  - spec/spec_helper.rb
320
451
  - spec/support/define_struct.rb
452
+ - spec/support/matchers.rb
453
+ - spec/support/predicates_integration.rb
321
454
  - spec/unit/error_compiler_spec.rb
322
455
  - spec/unit/hint_compiler_spec.rb
323
456
  - spec/unit/input_processor_compiler/form_spec.rb
324
457
  - spec/unit/input_processor_compiler/json_spec.rb
458
+ - spec/unit/predicate_registry_spec.rb
325
459
  - spec/unit/schema/key_spec.rb
326
460
  - spec/unit/schema/rule_spec.rb
327
461
  - spec/unit/schema/value_spec.rb
@@ -1,15 +0,0 @@
1
- module Dry
2
- module Validation
3
- class Schema
4
- class Attr < Key
5
- def self.type
6
- :attr
7
- end
8
-
9
- def class
10
- Attr
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,122 +0,0 @@
1
- RSpec.describe Dry::Validation::Schema, 'defining attr-based schema' do
2
- describe 'with a flat structure' do
3
- subject(:schema) do
4
- Dry::Validation.Schema do
5
- attr(:email).required
6
- attr(:age) { none? | (int? & gt?(18)) }
7
- end
8
- end
9
-
10
- let(:model) { Class.new(OpenStruct) }
11
-
12
- it 'passes when input is valid' do
13
- expect(schema.(model.new(email: 'jane@doe', age: 19))).to be_success
14
- expect(schema.(model.new(email: 'jane@doe', age: nil))).to be_success
15
- end
16
-
17
- it 'fails when input is not valid' do
18
- expect(schema.(model.new(email: 'jane@doe', age: 17))).to_not be_success
19
- end
20
- end
21
-
22
- describe 'with nested structures' do
23
- subject(:schema) do
24
- Dry::Validation.Schema do
25
- attr(:email).required
26
-
27
- attr(:age) { none? | (int? & gt?(18)) }
28
-
29
- attr(:address) do
30
- attr(:city) { min_size?(3) }
31
-
32
- attr(:street).required
33
-
34
- attr(:country) do
35
- attr(:name).required
36
- attr(:code).required
37
- end
38
- end
39
-
40
- attr(:phone_numbers) do
41
- array? { each(&:str?) }
42
- end
43
- end
44
- end
45
-
46
- let(:input) do
47
- OpenStruct.new(
48
- email: 'jane@doe.org',
49
- age: 19,
50
- address: OpenStruct.new(
51
- city: 'NYC', street: 'Street 1/2', country: OpenStruct.new(code: 'US', name: 'USA')
52
- ),
53
- phone_numbers: [
54
- '123456', '234567'
55
- ]
56
- )
57
- end
58
-
59
- describe '#messages' do
60
- it 'returns compiled error messages' do
61
- input.email = ''
62
-
63
- expect(schema.(input).messages).to eql(
64
- email: ['must be filled']
65
- )
66
- end
67
- end
68
-
69
- describe '#call' do
70
- it 'passes when attributes are valid' do
71
- expect(schema.(input)).to be_success
72
- end
73
-
74
- it 'validates presence of an email and min age value' do
75
- input.email = ''
76
- input.age = 18
77
-
78
- expect(schema.(input).messages).to eql(
79
- email: ['must be filled'], age: ['must be greater than 18']
80
- )
81
- end
82
-
83
- it 'validates type of age value' do
84
- input.age = '18'
85
-
86
- expect(schema.(input).messages).to eql(
87
- age: ['must be an integer', 'must be greater than 18']
88
- )
89
- end
90
-
91
- it 'validates presence of phone_number keys' do
92
- input.phone_numbers = nil
93
-
94
- expect(schema.(input).messages).to eql(
95
- phone_numbers: ['must be an array']
96
- )
97
- end
98
-
99
- it 'validates presence of address street & county & min size of the city' do
100
- input.address.city = 'NY'
101
- input.address.street = nil
102
- input.address.country.name = nil
103
-
104
- expect(schema.(input).messages).to eql(
105
- address: {
106
- street: ['must be filled'],
107
- country: { name: ['must be filled'] },
108
- city: ['size cannot be less than 3']
109
- }
110
- )
111
- end
112
-
113
- it 'validates each phone number' do
114
- input.phone_numbers = ['123', 312]
115
-
116
- expect(schema.(input).messages).to eql(
117
- phone_numbers: { 1 => ['must be a string'] }
118
- )
119
- end
120
- end
121
- end
122
- end