ruby-livr 2.0.0 → 2.1.0

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.
Files changed (92) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +23 -0
  3. data/.gitignore +1 -0
  4. data/Readme.md +2 -2
  5. data/lib/livr/aliased_rule.rb +11 -5
  6. data/lib/livr/rule.rb +13 -0
  7. data/lib/livr/rules/common.rb +1 -2
  8. data/lib/livr/rules/meta.rb +43 -12
  9. data/lib/livr/rules/modifiers.rb +10 -10
  10. data/lib/livr/rules/numeric.rb +5 -5
  11. data/lib/livr/rules/special.rb +14 -9
  12. data/lib/livr/validator.rb +7 -2
  13. data/lib/livr.rb +2 -0
  14. data/ruby-livr.gemspec +5 -4
  15. data/spec/01-test_suite_spec.rb +7 -2
  16. data/spec/02-aliases_spec.rb +30 -1
  17. data/spec/04-custom_filters_spec.rb +12 -1
  18. data/spec/06-primitive_values_spec.rb +133 -0
  19. data/spec/test_suite/aliases_negative/02-address/aliases.json +2 -2
  20. data/spec/test_suite/aliases_negative/02-address/input.json +2 -2
  21. data/spec/test_suite/aliases_positive/01-adult_age/input.json +1 -0
  22. data/spec/test_suite/aliases_positive/01-adult_age/output.json +1 -0
  23. data/spec/test_suite/aliases_positive/01-adult_age/rules.json +2 -0
  24. data/spec/test_suite/aliases_positive/02-address/aliases.json +2 -2
  25. data/spec/test_suite/aliases_positive/02-address/input.json +1 -1
  26. data/spec/test_suite/aliases_positive/02-address/output.json +1 -1
  27. data/spec/test_suite/negative/01-required/errors.json +4 -1
  28. data/spec/test_suite/negative/01-required/input.json +1 -0
  29. data/spec/test_suite/negative/01-required/rules.json +5 -1
  30. data/spec/test_suite/negative/03-one_of/errors.json +2 -0
  31. data/spec/test_suite/negative/03-one_of/input.json +2 -0
  32. data/spec/test_suite/negative/03-one_of/rules.json +9 -7
  33. data/spec/test_suite/negative/12-positive_decimal/errors.json +1 -0
  34. data/spec/test_suite/negative/12-positive_decimal/input.json +1 -0
  35. data/spec/test_suite/negative/12-positive_decimal/rules.json +1 -0
  36. data/spec/test_suite/negative/16-email/errors.json +22 -0
  37. data/spec/test_suite/negative/16-email/input.json +23 -0
  38. data/spec/test_suite/negative/16-email/rules.json +23 -0
  39. data/spec/test_suite/negative/17-equal_to_field/errors.json +4 -0
  40. data/spec/test_suite/negative/17-equal_to_field/input.json +5 -0
  41. data/spec/test_suite/negative/17-equal_to_field/rules.json +4 -0
  42. data/spec/test_suite/negative/18-nested_object/input.json +1 -1
  43. data/spec/test_suite/negative/21-list_of_different_objects/errors.json +6 -1
  44. data/spec/test_suite/negative/21-list_of_different_objects/input.json +23 -1
  45. data/spec/test_suite/negative/21-list_of_different_objects/rules.json +36 -1
  46. data/spec/test_suite/negative/23-url/errors.json +2 -0
  47. data/spec/test_suite/negative/23-url/input.json +2 -0
  48. data/spec/test_suite/negative/23-url/rules.json +2 -0
  49. data/spec/test_suite/negative/24-iso_date/errors.json +6 -0
  50. data/spec/test_suite/negative/24-iso_date/input.json +6 -0
  51. data/spec/test_suite/negative/24-iso_date/rules.json +6 -0
  52. data/spec/test_suite/negative/25-eq/rules.json +7 -7
  53. data/spec/test_suite/negative/28-variable_object/errors.json +9 -1
  54. data/spec/test_suite/negative/28-variable_object/input.json +9 -1
  55. data/spec/test_suite/negative/28-variable_object/rules.json +57 -1
  56. data/spec/test_suite/negative/29-or/errors.json +3 -0
  57. data/spec/test_suite/negative/29-or/input.json +1 -0
  58. data/spec/test_suite/negative/29-or/rules.json +3 -0
  59. data/spec/test_suite/positive/01-required/input.json +5 -1
  60. data/spec/test_suite/positive/01-required/output.json +4 -1
  61. data/spec/test_suite/positive/01-required/rules.json +4 -1
  62. data/spec/test_suite/positive/03-one_of/input.json +7 -3
  63. data/spec/test_suite/positive/03-one_of/output.json +7 -3
  64. data/spec/test_suite/positive/03-one_of/rules.json +8 -4
  65. data/spec/test_suite/positive/16-email/input.json +29 -0
  66. data/spec/test_suite/positive/16-email/output.json +28 -0
  67. data/spec/test_suite/positive/16-email/rules.json +28 -0
  68. data/spec/test_suite/positive/17-equal_to_field/input.json +3 -1
  69. data/spec/test_suite/positive/17-equal_to_field/output.json +2 -1
  70. data/spec/test_suite/positive/17-equal_to_field/rules.json +2 -1
  71. data/spec/test_suite/positive/18-nested_object/input.json +9 -1
  72. data/spec/test_suite/positive/18-nested_object/output.json +5 -0
  73. data/spec/test_suite/positive/18-nested_object/rules.json +10 -1
  74. data/spec/test_suite/positive/24-iso_date/input.json +2 -0
  75. data/spec/test_suite/positive/24-iso_date/output.json +2 -0
  76. data/spec/test_suite/positive/24-iso_date/rules.json +2 -0
  77. data/spec/test_suite/positive/25-eq/input.json +3 -3
  78. data/spec/test_suite/positive/25-eq/output.json +3 -3
  79. data/spec/test_suite/positive/25-eq/rules.json +4 -4
  80. data/spec/test_suite/positive/26-string/input.json +2 -2
  81. data/spec/test_suite/positive/26-string/output.json +2 -2
  82. data/spec/test_suite/positive/27-any_object/input.json +3 -2
  83. data/spec/test_suite/positive/27-any_object/output.json +3 -2
  84. data/spec/test_suite/positive/27-any_object/rules.json +2 -1
  85. data/spec/test_suite/positive/29-or/input.json +2 -0
  86. data/spec/test_suite/positive/29-or/output.json +2 -0
  87. data/spec/test_suite/positive/29-or/rules.json +3 -0
  88. data/spec/test_suite/positive/35-default/output.json +2 -1
  89. data/spec/test_suite/positive/35-default/rules.json +2 -1
  90. metadata +17 -14
  91. data/.travis.yml +0 -4
  92. data/Gemfile.lock +0 -45
@@ -0,0 +1,133 @@
1
+ require 'spec_helper.rb'
2
+
3
+ RSpec.describe "primitive values" do
4
+
5
+ it "iso_date: numbers and booleans are wrong dates" do
6
+ validator = LIVR::Validator.new(
7
+ "date1" => "iso_date",
8
+ "date2" => "iso_date",
9
+ "date3" => "iso_date"
10
+ )
11
+
12
+ output = validator.validate("date1" => 20200101, "date2" => 1.5, "date3" => true)
13
+
14
+ expect(output).to eq(false)
15
+ expect(validator.get_errors).to eq(
16
+ "date1" => "WRONG_DATE",
17
+ "date2" => "WRONG_DATE",
18
+ "date3" => "WRONG_DATE"
19
+ )
20
+ end
21
+
22
+ it "iso_date: only YYYY-MM-DD strings are dates" do
23
+ validator = LIVR::Validator.new(
24
+ "date1" => "iso_date",
25
+ "date2" => "iso_date",
26
+ "date3" => "iso_date",
27
+ "date4" => "iso_date"
28
+ )
29
+
30
+ output = validator.validate("date1" => "2020-01-1x", "date2" => "+020-01-01", "date3" => "2020-1-1-1", "date4" => "2020-01-01")
31
+
32
+ expect(output).to eq(false)
33
+ expect(validator.get_errors).to eq(
34
+ "date1" => "WRONG_DATE",
35
+ "date2" => "WRONG_DATE",
36
+ "date3" => "WRONG_DATE"
37
+ )
38
+ end
39
+
40
+ it "integer, positive_integer: strings are decimal numbers" do
41
+ validator = LIVR::Validator.new(
42
+ "int1" => "integer",
43
+ "int2" => "positive_integer",
44
+ "int3" => "positive_integer"
45
+ )
46
+
47
+ output = validator.validate("int1" => "010", "int2" => "09", "int3" => "0x10")
48
+
49
+ expect(output).to eq(false)
50
+ expect(validator.get_errors).to eq("int3" => "NOT_POSITIVE_INTEGER")
51
+
52
+ expect(validator.validate("int1" => "010", "int2" => "09")).to eq("int1" => 10, "int2" => 9)
53
+ end
54
+
55
+ it "numeric rules: underscores are not digits" do
56
+ validator = LIVR::Validator.new(
57
+ "number1" => "integer",
58
+ "number2" => "positive_integer",
59
+ "number3" => { "min_number" => 1 },
60
+ "number4" => { "number_between" => [1, 2000] }
61
+ )
62
+
63
+ output = validator.validate("number1" => "1_000", "number2" => "1_000", "number3" => "1_000", "number4" => "1_000.5")
64
+
65
+ expect(output).to eq(false)
66
+ expect(validator.get_errors).to eq(
67
+ "number1" => "NOT_INTEGER",
68
+ "number2" => "NOT_POSITIVE_INTEGER",
69
+ "number3" => "NOT_NUMBER",
70
+ "number4" => "NOT_NUMBER"
71
+ )
72
+ end
73
+
74
+ it "min_number, max_number, number_between: integers stay integers" do
75
+ validator = LIVR::Validator.new(
76
+ "number1" => { "min_number" => 18 },
77
+ "number2" => { "max_number" => 100 },
78
+ "number3" => { "number_between" => [1, 100] },
79
+ "number4" => { "number_between" => [1, 100] }
80
+ )
81
+
82
+ output = validator.validate("number1" => 32, "number2" => "33", "number3" => "35", "number4" => "1.5")
83
+
84
+ expect(output.values.map(&:class)).to eq([Integer, Integer, Integer, Float])
85
+ expect(output).to eq("number1" => 32, "number2" => 33, "number3" => 35, "number4" => 1.5)
86
+ end
87
+
88
+ it "modifiers return strings to the next rules" do
89
+ validator = LIVR::Validator.new(
90
+ "email" => [ "required", "trim", "email", "to_lc" ],
91
+ "code" => [ "to_uc", { "one_of" => ["ABC"] } ],
92
+ "phone" => [ { "leave_only" => "0123456789" }, { "max_length" => 5 } ],
93
+ "name" => [ { "remove" => "-" }, "string" ]
94
+ )
95
+
96
+ output = validator.validate(
97
+ "email" => " User@Example.com ",
98
+ "code" => "abc",
99
+ "phone" => "12-34",
100
+ "name" => "a-b"
101
+ )
102
+
103
+ expect(output).to eq("email" => "user@example.com", "code" => "ABC", "phone" => "1234", "name" => "ab")
104
+ expect(output.values.map(&:class).uniq).to eq([String])
105
+ end
106
+
107
+ it "modifiers pass lists through unchanged" do
108
+ validator = LIVR::Validator.new(
109
+ "list1" => "trim",
110
+ "list2" => "to_lc",
111
+ "list3" => "to_uc",
112
+ "list4" => { "remove" => "1" },
113
+ "list5" => { "leave_only" => "1" }
114
+ )
115
+
116
+ input = { "list1" => [" a "], "list2" => ["A"], "list3" => ["a"], "list4" => [1, 2], "list5" => [1, 2] }
117
+
118
+ expect(validator.validate(input)).to eq(input)
119
+ end
120
+
121
+ it "required: false, 0 and whitespace are values" do
122
+ validator = LIVR::Validator.new(
123
+ "field1" => "required",
124
+ "field2" => "required",
125
+ "field3" => "required"
126
+ )
127
+
128
+ output = validator.validate("field1" => false, "field2" => 0, "field3" => " ")
129
+
130
+ expect(output).to eq("field1" => false, "field2" => 0, "field3" => " ")
131
+ end
132
+
133
+ end
@@ -4,7 +4,7 @@
4
4
  "rules": { "nested_object":{
5
5
  "street": "required",
6
6
  "zip": ["required", "positive_integer"],
7
- "city": {"one_of": ["Kiev", "Kharkiv"] }
7
+ "city": {"one_of": ["Kyiv", "Kharkiv"] }
8
8
  }}
9
9
  },
10
10
 
@@ -13,7 +13,7 @@
13
13
  "rules": { "nested_object":{
14
14
  "street": "required",
15
15
  "zip": ["required", "positive_integer"],
16
- "city": {"one_of": ["Kiev", "Kharkiv"] }
16
+ "city": {"one_of": ["Kyiv", "Kharkiv"] }
17
17
  }},
18
18
  "error": "WRONG_ADDRESS"
19
19
  }
@@ -2,12 +2,12 @@
2
2
  "address": {
3
3
  "street": "",
4
4
  "zip": -1232131,
5
- "city": "Moscow"
5
+ "city": "Lviv"
6
6
  },
7
7
  "address_custom_error": {
8
8
  "street": "My street",
9
9
  "zip": "12312",
10
- "city": "Moscow"
10
+ "city": "Lviv"
11
11
  },
12
12
  "extra_field": 12
13
13
  }
@@ -3,6 +3,7 @@
3
3
  "age2": 33,
4
4
  "age3": 35,
5
5
  "age4": 36,
6
+ "empty_age": "",
6
7
  "age1_custom_error": 37,
7
8
  "age2_custom_error": 38,
8
9
  "age3_custom_error": 100,
@@ -3,6 +3,7 @@
3
3
  "age2": 33,
4
4
  "age3": 35,
5
5
  "age4": 36,
6
+ "empty_age": "",
6
7
  "age1_custom_error": 37,
7
8
  "age2_custom_error": 38,
8
9
  "age3_custom_error": 100,
@@ -3,6 +3,8 @@
3
3
  "age2": ["adult_age"],
4
4
  "age3": [ { "adult_age": [] } ],
5
5
  "age4": { "adult_age": [] },
6
+ "empty_age": "adult_age",
7
+ "missed_age": "adult_age",
6
8
  "age1_custom_error": "adult_age_with_custom_error",
7
9
  "age2_custom_error": ["adult_age_with_custom_error"],
8
10
  "age3_custom_error": [ { "adult_age_with_custom_error": [] } ],
@@ -4,7 +4,7 @@
4
4
  "rules": { "nested_object":{
5
5
  "street": "required",
6
6
  "zip": ["required", "positive_integer"],
7
- "city": {"one_of": ["Kiev", "Kharkiv"] }
7
+ "city": {"one_of": ["Kyiv", "Kharkiv"] }
8
8
  }}
9
9
  },
10
10
 
@@ -13,7 +13,7 @@
13
13
  "rules": { "nested_object":{
14
14
  "street": "required",
15
15
  "zip": ["required", "positive_integer"],
16
- "city": {"one_of": ["Kiev", "Kharkiv"] }
16
+ "city": {"one_of": ["Kyiv", "Kharkiv"] }
17
17
  }},
18
18
  "error": "WRONG_ADDRESS"
19
19
  }
@@ -2,7 +2,7 @@
2
2
  "address": {
3
3
  "street": "My street",
4
4
  "zip": 1232131,
5
- "city": "Kiev"
5
+ "city": "Kyiv"
6
6
  },
7
7
  "address_custom_error": {
8
8
  "street": "My street",
@@ -2,7 +2,7 @@
2
2
  "address": {
3
3
  "street": "My street",
4
4
  "zip": 1232131,
5
- "city": "Kiev"
5
+ "city": "Kyiv"
6
6
  },
7
7
  "address_custom_error": {
8
8
  "street": "My street",
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "first_name": "REQUIRED",
3
3
  "last_name": "REQUIRED",
4
- "middle_name": "REQUIRED"
4
+ "middle_name": "REQUIRED",
5
+ "constructor": "REQUIRED",
6
+ "toString": "REQUIRED",
7
+ "hasOwnProperty": "REQUIRED"
5
8
  }
@@ -2,6 +2,7 @@
2
2
  "first_name": "",
3
3
  "last_name": null,
4
4
  "age": "25",
5
+ "__proto__": { "middle_name": "Some" },
5
6
 
6
7
  "value_is_hash": {"test": 1},
7
8
  "value_is_empty_hash": {},
@@ -6,5 +6,9 @@
6
6
  "value_is_hash": "required",
7
7
  "value_is_empty_hash": "required",
8
8
  "value_is_array": "required",
9
- "value_is_empty_array": "required"
9
+ "value_is_empty_array": "required",
10
+
11
+ "constructor": "required",
12
+ "toString": "required",
13
+ "hasOwnProperty": "required"
10
14
  }
@@ -2,7 +2,9 @@
2
2
  "city1": "NOT_ALLOWED_VALUE",
3
3
  "city2": "NOT_ALLOWED_VALUE",
4
4
  "city3": "NOT_ALLOWED_VALUE",
5
+ "city4": "NOT_ALLOWED_VALUE",
5
6
  "number1": "NOT_ALLOWED_VALUE",
7
+ "number2": "NOT_ALLOWED_VALUE",
6
8
 
7
9
  "value_is_hash": "FORMAT_ERROR",
8
10
  "value_is_empty_hash": "FORMAT_ERROR",
@@ -2,7 +2,9 @@
2
2
  "city1": "New York",
3
3
  "city2": "New York",
4
4
  "city3": "New York",
5
+ "city4": "New York",
5
6
  "number1": "1.0",
7
+ "number2": 40,
6
8
  "extra_city": "New York",
7
9
 
8
10
  "value_is_hash": {"test": 1},
@@ -1,11 +1,13 @@
1
1
  {
2
- "city1": { "one_of": [["Moscow", "Kiev" ]] },
3
- "city2": [{ "one_of": [["Moscow", "Kiev" ]] }],
4
- "city3": { "one_of": ["Moscow", "Kiev"] },
2
+ "city1": { "one_of": [["Lviv", "Kyiv" ]] },
3
+ "city2": [{ "one_of": [["Lviv", "Kyiv" ]] }],
4
+ "city3": { "one_of": ["Lviv", "Kyiv"] },
5
+ "city4": { "one_of": ["Kyiv", "Lviv", "Odesa", "Kharkiv"] },
5
6
  "number1": { "one_of": [1, "1.00", "1"] },
7
+ "number2": { "one_of": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39]] },
6
8
 
7
- "value_is_hash": { "one_of": [["Moscow", "Kiev" ]] },
8
- "value_is_empty_hash": { "one_of": [["Moscow", "Kiev" ]] },
9
- "value_is_array": { "one_of": [["Moscow", "Kiev" ]] },
10
- "value_is_empty_array": { "one_of": [["Moscow", "Kiev" ]] }
9
+ "value_is_hash": { "one_of": [["Lviv", "Kyiv" ]] },
10
+ "value_is_empty_hash": { "one_of": [["Lviv", "Kyiv" ]] },
11
+ "value_is_array": { "one_of": [["Lviv", "Kyiv" ]] },
12
+ "value_is_empty_array": { "one_of": [["Lviv", "Kyiv" ]] }
11
13
  }
@@ -2,6 +2,7 @@
2
2
  "number1": "NOT_POSITIVE_DECIMAL",
3
3
  "number2": "NOT_POSITIVE_DECIMAL",
4
4
  "number3": "NOT_POSITIVE_DECIMAL",
5
+ "number4": "NOT_POSITIVE_DECIMAL",
5
6
 
6
7
  "value_is_string": "NOT_POSITIVE_DECIMAL",
7
8
  "value_is_hash": "FORMAT_ERROR",
@@ -2,6 +2,7 @@
2
2
  "number1": "10.10.10",
3
3
  "number2": "0",
4
4
  "number3": -1.12,
5
+ "number4": "0.0",
5
6
  "empty_field": "",
6
7
  "extra_field": "100",
7
8
 
@@ -2,6 +2,7 @@
2
2
  "number1": "positive_decimal",
3
3
  "number2": ["positive_decimal"],
4
4
  "number3": [ { "positive_decimal": [] } ],
5
+ "number4": ["positive_decimal"],
5
6
  "empty_field": "positive_decimal",
6
7
 
7
8
  "value_is_string": "positive_decimal",
@@ -4,6 +4,28 @@
4
4
  "email3": "WRONG_EMAIL",
5
5
  "email4": "WRONG_EMAIL",
6
6
  "email5": "WRONG_EMAIL",
7
+ "email6": "WRONG_EMAIL",
8
+ "email7": "WRONG_EMAIL",
9
+ "email8": "WRONG_EMAIL",
10
+ "email9": "WRONG_EMAIL",
11
+ "email10": "WRONG_EMAIL",
12
+ "email11": "WRONG_EMAIL",
13
+ "email12": "WRONG_EMAIL",
14
+ "email13": "WRONG_EMAIL",
15
+ "email14": "WRONG_EMAIL",
16
+ "email15": "WRONG_EMAIL",
17
+ "email16": "WRONG_EMAIL",
18
+ "email17": "WRONG_EMAIL",
19
+ "email18": "WRONG_EMAIL",
20
+ "email19": "WRONG_EMAIL",
21
+ "email20": "WRONG_EMAIL",
22
+ "email21": "WRONG_EMAIL",
23
+ "email22": "WRONG_EMAIL",
24
+ "email23": "WRONG_EMAIL",
25
+ "email24": "WRONG_EMAIL",
26
+ "email25": "WRONG_EMAIL",
27
+ "email26": "WRONG_EMAIL",
28
+ "email27": "WRONG_EMAIL",
7
29
 
8
30
  "value_is_hash": "FORMAT_ERROR",
9
31
  "value_is_empty_hash": "FORMAT_ERROR",
@@ -4,6 +4,29 @@
4
4
  "email3": "test+test.t_e_s_t@ma_il.in.ua",
5
5
  "email4": "user name@gmail.com",
6
6
  "email5": "username@mail.c om",
7
+ "email6": "en ny@enny.devoffice.com",
8
+ "email7": "enny..tester@devoffice.com",
9
+ "email8": ".enny@enny.devoffice.com",
10
+ "email9": "enny.devoffice.com",
11
+ "email10": "test@test",
12
+ "email11": "tester@enny..devoffice.com",
13
+ "email12": "en(ny@enny.devoffice.com",
14
+ "email13": "en)ny@enny.devoffice.com",
15
+ "email14": "en[enny@devoffice.com",
16
+ "email15": "en]ny@devoffice.com",
17
+ "email16": "ho:rhe@tester.devoffice.com",
18
+ "email17": "enny;tester@devoffice.com",
19
+ "email18": "te,st@devoffice.com",
20
+ "email19": "test<er@devoffice.com",
21
+ "email20": "tes>ter@devoffice.com",
22
+ "email21": "tester@@devoffice.com",
23
+ "email22": "tester@tes ter.devoffice.com",
24
+ "email23": "@enny tm.devoffice.com",
25
+ "email24": "тестувальник@пошта.укр ",
26
+ "email25": "test@mail.com\n",
27
+ "email26": "te\nst@mail.com",
28
+ "email27": "test@ma\nil.com",
29
+
7
30
  "empty_field": "",
8
31
  "extra_field": "aaaa",
9
32
 
@@ -4,6 +4,29 @@
4
4
  "email3": [ { "email": [] } ],
5
5
  "email4": "email",
6
6
  "email5": "email",
7
+ "email6": "email",
8
+ "email7": "email",
9
+ "email8": "email",
10
+ "email9": "email",
11
+ "email10": "email",
12
+ "email11": "email",
13
+ "email12": "email",
14
+ "email13": "email",
15
+ "email14": "email",
16
+ "email15": "email",
17
+ "email16": "email",
18
+ "email17": "email",
19
+ "email18": "email",
20
+ "email19": "email",
21
+ "email20": "email",
22
+ "email21": "email",
23
+ "email22": "email",
24
+ "email23": "email",
25
+ "email24": "email",
26
+ "email25": "email",
27
+ "email26": "email",
28
+ "email27": "email",
29
+
7
30
  "empty_field": "email",
8
31
 
9
32
  "value_is_hash": "email",
@@ -2,6 +2,10 @@
2
2
  "field1": "FIELDS_NOT_EQUAL",
3
3
  "field2": "FIELDS_NOT_EQUAL",
4
4
  "field3": "FIELDS_NOT_EQUAL",
5
+ "same_number_exponent": "FIELDS_NOT_EQUAL",
6
+ "same_number_leading_zero": "FIELDS_NOT_EQUAL",
7
+ "same_number_space": "FIELDS_NOT_EQUAL",
8
+ "missing_other_field": "FIELDS_NOT_EQUAL",
5
9
 
6
10
  "value_is_hash": "FORMAT_ERROR",
7
11
  "value_is_empty_hash": "FORMAT_ERROR",
@@ -4,6 +4,11 @@
4
4
  "field3": "some value",
5
5
  "empty_field": "",
6
6
  "extra_field": "some value",
7
+ "number": "10",
8
+ "same_number_exponent": "1e1",
9
+ "same_number_leading_zero": "010",
10
+ "same_number_space": " 10",
11
+ "missing_other_field": "some value",
7
12
 
8
13
  "value_is_hash": {"test": 1},
9
14
  "value_is_empty_hash": {},
@@ -3,6 +3,10 @@
3
3
  "field2": { "equal_to_field": ["field1"] },
4
4
  "field3": { "equal_to_field": ["field1"] },
5
5
  "empty_field": { "equal_to_field": "field2" },
6
+ "same_number_exponent": { "equal_to_field": "number" },
7
+ "same_number_leading_zero": { "equal_to_field": "number" },
8
+ "same_number_space": { "equal_to_field": "number" },
9
+ "missing_other_field": { "equal_to_field": "missing_field" },
6
10
 
7
11
  "value_is_hash": { "equal_to_field": "field2" },
8
12
  "value_is_empty_hash": { "equal_to_field": "field2" },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "address": {
3
- "country": "Russia",
3
+ "country": "Poland",
4
4
  "zip": "AAA",
5
5
  "street": "",
6
6
  "building": "-10"
@@ -13,5 +13,10 @@
13
13
  },
14
14
  "FORMAT_ERROR",
15
15
  "FORMAT_ERROR"
16
- ]
16
+ ],
17
+ "only_wrong_items": ["FORMAT_ERROR", "FORMAT_ERROR", "FORMAT_ERROR", "FORMAT_ERROR", "FORMAT_ERROR"],
18
+ "valid_and_wrong_items": [null, "FORMAT_ERROR"],
19
+ "null_item": ["FORMAT_ERROR"],
20
+ "selector_is_not_string": ["FORMAT_ERROR", "FORMAT_ERROR"],
21
+ "selector_is_builtin_property": ["FORMAT_ERROR", "FORMAT_ERROR", "FORMAT_ERROR", "FORMAT_ERROR"]
17
22
  }
@@ -22,5 +22,27 @@
22
22
  },
23
23
  "Some Wrong Data"
24
24
  ],
25
- "users": "not an array"
25
+ "users": "not an array",
26
+ "only_wrong_items": [
27
+ "Some Wrong Data",
28
+ 10,
29
+ {"product_type": "wrongtype"},
30
+ {"name": "No product type"},
31
+ ["material"]
32
+ ],
33
+ "valid_and_wrong_items": [
34
+ {"product_type": "service", "name": "Service"},
35
+ "Some Wrong Data"
36
+ ],
37
+ "null_item": [null],
38
+ "selector_is_not_string": [
39
+ {"product_type": ["material"], "material_id": 1},
40
+ {"product_type": {"material": 1}, "material_id": 1}
41
+ ],
42
+ "selector_is_builtin_property": [
43
+ {"product_type": "constructor"},
44
+ {"product_type": "toString"},
45
+ {"product_type": "hasOwnProperty"},
46
+ {"product_type": "__proto__"}
47
+ ]
26
48
  }
@@ -13,5 +13,40 @@
13
13
  "name": ["required", {"max_length": 10} ]
14
14
  }
15
15
  }
16
- ]}]
16
+ ]}],
17
+
18
+ "only_wrong_items": { "list_of_different_objects": [
19
+ "product_type", {
20
+ "material": { "product_type": "required", "material_id": "positive_integer" },
21
+ "service": { "product_type": "required", "name": "required" }
22
+ }
23
+ ]},
24
+
25
+ "valid_and_wrong_items": { "list_of_different_objects": [
26
+ "product_type", {
27
+ "material": { "product_type": "required", "material_id": "positive_integer" },
28
+ "service": { "product_type": "required", "name": "required" }
29
+ }
30
+ ]},
31
+
32
+ "null_item": { "list_of_different_objects": [
33
+ "product_type", {
34
+ "material": { "product_type": "required", "material_id": "positive_integer" },
35
+ "service": { "product_type": "required", "name": "required" }
36
+ }
37
+ ]},
38
+
39
+ "selector_is_not_string": { "list_of_different_objects": [
40
+ "product_type", {
41
+ "material": { "product_type": "required", "material_id": "positive_integer" },
42
+ "service": { "product_type": "required", "name": "required" }
43
+ }
44
+ ]},
45
+
46
+ "selector_is_builtin_property": { "list_of_different_objects": [
47
+ "product_type", {
48
+ "material": { "product_type": "required", "material_id": "positive_integer" },
49
+ "service": { "product_type": "required", "name": "required" }
50
+ }
51
+ ]}
17
52
  }
@@ -2,6 +2,8 @@
2
2
  "url1": "WRONG_URL",
3
3
  "url2": "WRONG_URL",
4
4
  "url3": "WRONG_URL",
5
+ "url4": "WRONG_URL",
6
+ "url5": "WRONG_URL",
5
7
 
6
8
  "value_is_hash": "FORMAT_ERROR",
7
9
  "value_is_empty_hash": "FORMAT_ERROR",
@@ -2,6 +2,8 @@
2
2
  "url1": "www.google.com",
3
3
  "url2": "ftp://facebook.com",
4
4
  "url3": "http://g_oogle.com",
5
+ "url4": "https://google.com\n",
6
+ "url5": "http://webbylab.com/?param_1=123\n",
5
7
  "empty_field": "",
6
8
  "extra_field": "aaaa",
7
9
 
@@ -2,6 +2,8 @@
2
2
  "url1": "url",
3
3
  "url2": { "url": [] },
4
4
  "url3": [ { "url": [] } ],
5
+ "url4": "url",
6
+ "url5": "url",
5
7
  "empty_field": "url",
6
8
 
7
9
  "value_is_hash": "url",
@@ -2,6 +2,12 @@
2
2
  "iso_date1": "WRONG_DATE",
3
3
  "iso_date2": "WRONG_DATE",
4
4
  "iso_date3": "WRONG_DATE",
5
+ "iso_date4": "WRONG_DATE",
6
+ "iso_date5": "WRONG_DATE",
7
+ "iso_date6": "WRONG_DATE",
8
+ "iso_date7": "WRONG_DATE",
9
+ "iso_date8": "WRONG_DATE",
10
+ "iso_date9": "WRONG_DATE",
5
11
  "like_iso_date": "WRONG_DATE",
6
12
 
7
13
  "value_is_hash": "FORMAT_ERROR",
@@ -2,6 +2,12 @@
2
2
  "iso_date1": "2014-13-10",
3
3
  "iso_date2": "2011-02-29",
4
4
  "iso_date3": "2014-10-10T22:22",
5
+ "iso_date4": "1900-02-29",
6
+ "iso_date5": "2024-00-10",
7
+ "iso_date6": "2024-01-00",
8
+ "iso_date7": "2024-04-31",
9
+ "iso_date8": "2024-1-01",
10
+ "iso_date9": "2024-01-01\n",
5
11
  "like_iso_date":"aaaa-bb-cc",
6
12
  "empty_field": "",
7
13
  "extra_field": "aaaa",
@@ -2,6 +2,12 @@
2
2
  "iso_date1": "iso_date",
3
3
  "iso_date2": { "iso_date": [] },
4
4
  "iso_date3": [ { "iso_date": [] } ],
5
+ "iso_date4": "iso_date",
6
+ "iso_date5": "iso_date",
7
+ "iso_date6": "iso_date",
8
+ "iso_date7": "iso_date",
9
+ "iso_date8": "iso_date",
10
+ "iso_date9": "iso_date",
5
11
  "like_iso_date": [ { "iso_date": [] } ],
6
12
  "empty_field": "iso_date",
7
13