schemacop 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/VERSION +1 -1
- data/doc/Schemacop.html +1 -1
- data/doc/Schemacop/Exceptions.html +1 -1
- data/doc/Schemacop/Exceptions/Base.html +1 -1
- data/doc/Schemacop/Exceptions/InvalidSchema.html +1 -1
- data/doc/Schemacop/Exceptions/Validation.html +1 -1
- data/doc/Schemacop/Validator.html +6 -6
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/top-level-namespace.html +1 -1
- data/lib/schemacop/validator.rb +32 -26
- data/schemacop.gemspec +4 -4
- data/test/schemacop_validator_test.rb +85 -25
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 461a65a27019c789e45d30f6d5be819c214a0b0a
|
4
|
+
data.tar.gz: ee57b67c3b810a9602e6914e151f86dba6d8b55f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b380fbdc36ab0a3ddda2b646128d6f300303ca4181765a84b32c1f499d5b081dcdaf88b8bb6b58325174c08f759c4308aa793c04cef53ad39638de4052eb6a7f
|
7
|
+
data.tar.gz: 8424d9820513500bd7616fcc5d13b80793b1d4e773c19255820cf40f7097e53ec194e306fc2fa9f3ea36482677602b2e89f7d75d26802deb4d7e60c59556f47e
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## master (unreleased)
|
4
|
+
|
5
|
+
### New features
|
6
|
+
|
7
|
+
### Bug fixes
|
8
|
+
|
9
|
+
### Changes
|
10
|
+
|
11
|
+
## 1.0.1 (2016-06-07)
|
12
|
+
|
13
|
+
### Bug fixes
|
14
|
+
|
15
|
+
* Fixed bug which didn't allow unspecified hash contents
|
16
|
+
* Fixed bug which didn't allow mixed array type specifications
|
17
|
+
|
18
|
+
## 1.0.0 (2016-06-06)
|
19
|
+
|
20
|
+
* Initial stable release
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/doc/Schemacop.html
CHANGED
@@ -199,7 +199,7 @@
|
|
199
199
|
</div>
|
200
200
|
|
201
201
|
<div id="footer">
|
202
|
-
Generated on
|
202
|
+
Generated on Tue Jun 7 10:37:13 2016 by
|
203
203
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
204
204
|
0.8.7.6 (ruby-2.0.0).
|
205
205
|
</div>
|
@@ -106,7 +106,7 @@
|
|
106
106
|
</div>
|
107
107
|
|
108
108
|
<div id="footer">
|
109
|
-
Generated on
|
109
|
+
Generated on Tue Jun 7 10:37:14 2016 by
|
110
110
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
111
111
|
0.8.7.6 (ruby-2.0.0).
|
112
112
|
</div>
|
@@ -118,7 +118,7 @@
|
|
118
118
|
</div>
|
119
119
|
|
120
120
|
<div id="footer">
|
121
|
-
Generated on
|
121
|
+
Generated on Tue Jun 7 10:37:14 2016 by
|
122
122
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
123
123
|
0.8.7.6 (ruby-2.0.0).
|
124
124
|
</div>
|
@@ -132,7 +132,7 @@
|
|
132
132
|
</div>
|
133
133
|
|
134
134
|
<div id="footer">
|
135
|
-
Generated on
|
135
|
+
Generated on Tue Jun 7 10:37:14 2016 by
|
136
136
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
137
137
|
0.8.7.6 (ruby-2.0.0).
|
138
138
|
</div>
|
@@ -133,7 +133,7 @@ schema definition.</p>
|
|
133
133
|
</div>
|
134
134
|
|
135
135
|
<div id="footer">
|
136
|
-
Generated on
|
136
|
+
Generated on Tue Jun 7 10:37:14 2016 by
|
137
137
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
138
138
|
0.8.7.6 (ruby-2.0.0).
|
139
139
|
</div>
|
@@ -108,11 +108,11 @@
|
|
108
108
|
|
109
109
|
</dt>
|
110
110
|
<dd><pre class="code"><span class='lbrace'>{</span>
|
111
|
-
<span class='label'>hash:</span>
|
112
|
-
<span class='label'>array:</span>
|
113
|
-
<span class='label'>string:</span>
|
114
|
-
<span class='label'>integer:</span>
|
115
|
-
<span class='label'>boolean:</span>
|
111
|
+
<span class='label'>hash:</span> <span class='lbracket'>[</span><span class='const'>Hash</span><span class='rbracket'>]</span><span class='comma'>,</span>
|
112
|
+
<span class='label'>array:</span> <span class='lbracket'>[</span><span class='const'>Array</span><span class='rbracket'>]</span><span class='comma'>,</span>
|
113
|
+
<span class='label'>string:</span> <span class='lbracket'>[</span><span class='const'>String</span><span class='rbracket'>]</span><span class='comma'>,</span>
|
114
|
+
<span class='label'>integer:</span> <span class='lbracket'>[</span><span class='const'>Integer</span><span class='rbracket'>]</span><span class='comma'>,</span>
|
115
|
+
<span class='label'>boolean:</span> <span class='lbracket'>[</span><span class='const'>TrueClass</span><span class='comma'>,</span> <span class='const'>FalseClass</span><span class='rbracket'>]</span>
|
116
116
|
<span class='rbrace'>}</span></pre></dd>
|
117
117
|
|
118
118
|
</dl>
|
@@ -245,7 +245,7 @@
|
|
245
245
|
</div>
|
246
246
|
|
247
247
|
<div id="footer">
|
248
|
-
Generated on
|
248
|
+
Generated on Tue Jun 7 10:37:14 2016 by
|
249
249
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
250
250
|
0.8.7.6 (ruby-2.0.0).
|
251
251
|
</div>
|
data/doc/_index.html
CHANGED
@@ -168,7 +168,7 @@
|
|
168
168
|
</div>
|
169
169
|
|
170
170
|
<div id="footer">
|
171
|
-
Generated on
|
171
|
+
Generated on Tue Jun 7 10:37:13 2016 by
|
172
172
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
173
173
|
0.8.7.6 (ruby-2.0.0).
|
174
174
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -393,7 +393,7 @@ concerning their name and the structure of their README file.</p>
|
|
393
393
|
</div></div>
|
394
394
|
|
395
395
|
<div id="footer">
|
396
|
-
Generated on
|
396
|
+
Generated on Tue Jun 7 10:37:13 2016 by
|
397
397
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
398
398
|
0.8.7.6 (ruby-2.0.0).
|
399
399
|
</div>
|
data/doc/index.html
CHANGED
@@ -393,7 +393,7 @@ concerning their name and the structure of their README file.</p>
|
|
393
393
|
</div></div>
|
394
394
|
|
395
395
|
<div id="footer">
|
396
|
-
Generated on
|
396
|
+
Generated on Tue Jun 7 10:37:13 2016 by
|
397
397
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
398
398
|
0.8.7.6 (ruby-2.0.0).
|
399
399
|
</div>
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Tue Jun 7 10:37:13 2016 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.7.6 (ruby-2.0.0).
|
109
109
|
</div>
|
data/lib/schemacop/validator.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Schemacop
|
2
2
|
class Validator
|
3
3
|
TYPE_ALIASES = {
|
4
|
-
hash:
|
5
|
-
array:
|
6
|
-
string:
|
7
|
-
integer:
|
8
|
-
boolean:
|
4
|
+
hash: [Hash],
|
5
|
+
array: [Array],
|
6
|
+
string: [String],
|
7
|
+
integer: [Integer],
|
8
|
+
boolean: [TrueClass, FalseClass]
|
9
9
|
}
|
10
10
|
|
11
11
|
# Validates `data` against `schema` and throws an exception on missmatch.
|
@@ -25,42 +25,47 @@ module Schemacop
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def prepare_schema(schema)
|
28
|
-
schema = { types: schema } unless schema.is_a?
|
28
|
+
schema = { types: schema } unless schema.is_a?(Hash)
|
29
29
|
|
30
30
|
if schema.include?(:type)
|
31
|
-
schema[:types] = schema.delete
|
31
|
+
schema[:types] = schema.delete(:type)
|
32
32
|
else
|
33
33
|
schema[:types] = :array unless schema[:array].nil?
|
34
34
|
schema[:types] = :hash unless schema[:hash].nil?
|
35
35
|
end
|
36
36
|
|
37
37
|
schema[:types] = [*schema[:types]]
|
38
|
+
schema[:types].map! do |type|
|
39
|
+
alias_type = TYPE_ALIASES.select { |_, v| v.include?(type) }.keys.first
|
40
|
+
type = alias_type unless alias_type.nil?
|
41
|
+
type
|
42
|
+
end
|
43
|
+
|
38
44
|
schema[:types].each do |type|
|
39
45
|
if type == :hash
|
40
|
-
if schema.include?
|
41
|
-
schema[:hash] = schema.delete
|
46
|
+
if schema.include?(:fields)
|
47
|
+
schema[:hash] = schema.delete(:fields)
|
42
48
|
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
schema[:hash] = schema[:hash] || {}
|
51
|
+
if schema[:hash].is_a?(Hash)
|
52
|
+
schema[:hash].each do |key, value|
|
53
|
+
schema[:hash][key] = prepare_schema(value)
|
47
54
|
end
|
48
55
|
end
|
49
56
|
end
|
50
57
|
|
51
|
-
if type == :array
|
52
|
-
schema[:array] = prepare_schema schema[:array]
|
53
|
-
end
|
58
|
+
schema[:array] = prepare_schema(schema[:array]) if type == :array
|
54
59
|
end
|
55
60
|
|
56
61
|
schema
|
57
62
|
end
|
58
63
|
|
59
64
|
def assign_data_type(type)
|
60
|
-
if type.is_a?
|
65
|
+
if type.is_a?(Symbol)
|
61
66
|
fail Exceptions::InvalidSchema, "Type alias #{type} is not supported." if TYPE_ALIASES[type].nil?
|
62
67
|
TYPE_ALIASES[type]
|
63
|
-
elsif type.is_a?
|
68
|
+
elsif type.is_a?(String)
|
64
69
|
type.to_s.classify.safe_constantize
|
65
70
|
else
|
66
71
|
type
|
@@ -86,7 +91,7 @@ module Schemacop
|
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
89
|
-
|
94
|
+
if schema[:types].present? && !supported_types.any? { |t| data.is_a?(t) }
|
90
95
|
fail Exceptions::Validation, "Property at path #{path} must be of type #{supported_types.inspect}."
|
91
96
|
end
|
92
97
|
|
@@ -94,8 +99,7 @@ module Schemacop
|
|
94
99
|
# Check for allowed values
|
95
100
|
# ---------------------------------------------------------------
|
96
101
|
if schema[:allowed_values] && !schema[:allowed_values].include?(data)
|
97
|
-
fail Exceptions::Validation,
|
98
|
-
"Value #{data.inspect} of property at path #{path} is not valid. Valid are: #{schema[:allowed_values].inspect}."
|
102
|
+
fail Exceptions::Validation, "Value #{data.inspect} of property at path #{path} is not valid. Valid are: #{schema[:allowed_values].inspect}."
|
99
103
|
end
|
100
104
|
|
101
105
|
# ---------------------------------------------------------------
|
@@ -108,11 +112,13 @@ module Schemacop
|
|
108
112
|
fail Exceptions::InvalidSchema, "Missing schema entry :hash at path #{path}."
|
109
113
|
end
|
110
114
|
|
111
|
-
data_keys = data.keys.collect(&:to_s)
|
112
115
|
schema_keys = schema[:hash].keys.collect(&:to_s)
|
116
|
+
unless schema_keys.empty?
|
117
|
+
data_keys = data.keys.collect(&:to_s)
|
113
118
|
|
114
|
-
|
115
|
-
|
119
|
+
unless (obsolete_keys = data_keys - schema_keys).empty?
|
120
|
+
fail Exceptions::Validation, "Obsolete keys at path #{path}: #{obsolete_keys.inspect}."
|
121
|
+
end
|
116
122
|
end
|
117
123
|
|
118
124
|
schema[:hash].each do |sub_key, sub_schema|
|
@@ -125,12 +131,12 @@ module Schemacop
|
|
125
131
|
fail Exceptions::Validation, "Property at path #{path}.#{sub_key} can't be null."
|
126
132
|
end
|
127
133
|
else
|
128
|
-
validate_branch
|
134
|
+
validate_branch("#{path}.#{sub_key}", sub_schema, data[sub_key])
|
129
135
|
end
|
130
136
|
end
|
131
|
-
elsif schema[:types].include?
|
137
|
+
elsif schema[:types].include?(:array)
|
132
138
|
data.each_with_index do |value, index|
|
133
|
-
validate_branch
|
139
|
+
validate_branch("#{path}[#{index}]", schema[:array], value)
|
134
140
|
end
|
135
141
|
end
|
136
142
|
end
|
data/schemacop.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 1.0.
|
2
|
+
# stub: schemacop 1.0.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "schemacop"
|
6
|
-
s.version = "1.0.
|
6
|
+
s.version = "1.0.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Sitrox"]
|
10
|
-
s.date = "2016-06-
|
11
|
-
s.files = [".gitignore", ".releaser_config", ".rubocop.yml", ".travis.yml", ".yardopts", "Gemfile", "LICENSE", "README.md", "RUBY_VERSION", "Rakefile", "VERSION", "doc/Schemacop.html", "doc/Schemacop/Exceptions.html", "doc/Schemacop/Exceptions/Base.html", "doc/Schemacop/Exceptions/InvalidSchema.html", "doc/Schemacop/Exceptions/Validation.html", "doc/Schemacop/Validator.html", "doc/_index.html", "doc/class_list.html", "doc/css/common.css", "doc/css/full_list.css", "doc/css/style.css", "doc/file.README.html", "doc/file_list.html", "doc/frames.html", "doc/index.html", "doc/js/app.js", "doc/js/full_list.js", "doc/js/jquery.js", "doc/method_list.html", "doc/top-level-namespace.html", "lib/schemacop.rb", "lib/schemacop/exceptions.rb", "lib/schemacop/validator.rb", "schemacop.gemspec", "test/schemacop_validator_test.rb"]
|
10
|
+
s.date = "2016-06-07"
|
11
|
+
s.files = [".gitignore", ".releaser_config", ".rubocop.yml", ".travis.yml", ".yardopts", "CHANGELOG.md", "Gemfile", "LICENSE", "README.md", "RUBY_VERSION", "Rakefile", "VERSION", "doc/Schemacop.html", "doc/Schemacop/Exceptions.html", "doc/Schemacop/Exceptions/Base.html", "doc/Schemacop/Exceptions/InvalidSchema.html", "doc/Schemacop/Exceptions/Validation.html", "doc/Schemacop/Validator.html", "doc/_index.html", "doc/class_list.html", "doc/css/common.css", "doc/css/full_list.css", "doc/css/style.css", "doc/file.README.html", "doc/file_list.html", "doc/frames.html", "doc/index.html", "doc/js/app.js", "doc/js/full_list.js", "doc/js/jquery.js", "doc/method_list.html", "doc/top-level-namespace.html", "lib/schemacop.rb", "lib/schemacop/exceptions.rb", "lib/schemacop/validator.rb", "schemacop.gemspec", "test/schemacop_validator_test.rb"]
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.rubygems_version = "2.1.11"
|
14
14
|
s.summary = "Schemacop validates ruby structures consisting of nested hashes and arrays against simple schema definitions."
|
@@ -10,10 +10,13 @@ class SchemacopValidatorTest < Minitest::Test
|
|
10
10
|
|
11
11
|
def test_short_type_schema
|
12
12
|
assert_schema({ type: :array, array: :string }, %w(Hello world))
|
13
|
+
assert_schema({ type: [Array], array: :string }, %w(Hello world))
|
13
14
|
assert_schema({ array: :string }, %w(Hello world))
|
14
15
|
assert_schema({ hash: { first_name: :string, last_name: :string } }, first_name: 'John', last_name: 'Doe')
|
15
16
|
|
16
|
-
assert_schema_failure({ type: :array }, %w(Hello world))
|
17
|
+
assert_schema_failure({ type: :array, array: :integer }, %w(Hello world))
|
18
|
+
assert_schema_failure({ type: Array, array: :string }, [1, 2, 3])
|
19
|
+
assert_schema_failure({ type: [Array], array: :integer }, %w(Hello world))
|
17
20
|
end
|
18
21
|
|
19
22
|
def test_many_types_schema
|
@@ -50,6 +53,63 @@ class SchemacopValidatorTest < Minitest::Test
|
|
50
53
|
assert_schema(schema_rules, id: 'XYZ', name: 'John Doe', meta: { groups: [1, 2, 3], birthday: Date.today })
|
51
54
|
end
|
52
55
|
|
56
|
+
def test_hash_without_specification
|
57
|
+
schema_rules = {
|
58
|
+
type: :hash
|
59
|
+
}
|
60
|
+
|
61
|
+
assert_schema(schema_rules, user: 'hello')
|
62
|
+
assert_schema(schema_rules, user: :world)
|
63
|
+
assert_schema(schema_rules, user: 123)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_array_without_specification
|
67
|
+
schema_rules = {
|
68
|
+
type: :array
|
69
|
+
}
|
70
|
+
|
71
|
+
assert_schema(schema_rules, [1, 'hello', :world])
|
72
|
+
assert_schema(schema_rules, [])
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_hash_attributes_without_specification
|
76
|
+
schema_rules = {
|
77
|
+
type: :hash,
|
78
|
+
hash: {
|
79
|
+
user: { type: :hash, null: true }
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
assert_schema(schema_rules, user: { foo: :bar })
|
84
|
+
assert_schema(schema_rules, user: nil)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_array_in_hash_without_specification
|
88
|
+
schema_rules = {
|
89
|
+
type: Hash,
|
90
|
+
hash: {
|
91
|
+
types: { type: :array, null: true }
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
assert_schema(schema_rules, types: ['test', 1, :hello])
|
96
|
+
assert_schema(schema_rules, types: [])
|
97
|
+
assert_schema(schema_rules, types: nil)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_array_in_hash_with_multiple_types
|
101
|
+
schema_rules = {
|
102
|
+
type: :hash,
|
103
|
+
hash: {
|
104
|
+
types: { type: Array, array: [Integer, String] }
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
assert_schema(schema_rules, types: ['test', 1])
|
109
|
+
assert_schema(schema_rules, types: [])
|
110
|
+
assert_schema_failure(schema_rules, types: ['test', 1, :hello_world])
|
111
|
+
end
|
112
|
+
|
53
113
|
def test_nested_hash_schema
|
54
114
|
schema_rules = {
|
55
115
|
type: :hash,
|
@@ -77,13 +137,13 @@ class SchemacopValidatorTest < Minitest::Test
|
|
77
137
|
}
|
78
138
|
}
|
79
139
|
|
80
|
-
assert_schema
|
81
|
-
assert_schema
|
82
|
-
assert_schema
|
140
|
+
assert_schema(schema_rules, name: 'John Doe')
|
141
|
+
assert_schema(schema_rules, name: '')
|
142
|
+
assert_schema(schema_rules, name: nil)
|
83
143
|
|
84
|
-
assert_schema_failure
|
85
|
-
assert_schema_failure
|
86
|
-
assert_schema_failure
|
144
|
+
assert_schema_failure(schema_rules, name: 123)
|
145
|
+
assert_schema_failure(schema_rules, name: true)
|
146
|
+
assert_schema_failure(schema_rules, name: [])
|
87
147
|
end
|
88
148
|
|
89
149
|
def test_array_hash_old_schema
|
@@ -98,13 +158,13 @@ class SchemacopValidatorTest < Minitest::Test
|
|
98
158
|
}
|
99
159
|
}
|
100
160
|
|
101
|
-
assert_schema
|
161
|
+
assert_schema(schema_rules, [{ name: 'John', required: true }, { name: 'Alex', required: false }])
|
102
162
|
|
103
|
-
assert_schema_failure
|
104
|
-
assert_schema_failure
|
105
|
-
assert_schema_failure
|
106
|
-
assert_schema_failure
|
107
|
-
assert_schema_failure
|
163
|
+
assert_schema_failure(schema_rules, name: 'John Doe')
|
164
|
+
assert_schema_failure(schema_rules, [{ name: 'John Doe' }])
|
165
|
+
assert_schema_failure(schema_rules, [{ required: true }])
|
166
|
+
assert_schema_failure(schema_rules, [{ name: 0, required: true }])
|
167
|
+
assert_schema_failure(schema_rules, [{ name: 'John Doe', required: 'string' }])
|
108
168
|
end
|
109
169
|
|
110
170
|
def test_fields_array_old_schema
|
@@ -120,12 +180,12 @@ class SchemacopValidatorTest < Minitest::Test
|
|
120
180
|
}
|
121
181
|
}
|
122
182
|
|
123
|
-
assert_schema
|
124
|
-
assert_schema
|
183
|
+
assert_schema(schema_rules, ids: [])
|
184
|
+
assert_schema(schema_rules, ids: [1, 2, 3])
|
125
185
|
|
126
|
-
assert_schema_failure
|
127
|
-
assert_schema_failure
|
128
|
-
assert_schema_failure
|
186
|
+
assert_schema_failure(schema_rules, ids: [1, '2'])
|
187
|
+
assert_schema_failure(schema_rules, ids: '3')
|
188
|
+
assert_schema_failure(schema_rules, ids: nil)
|
129
189
|
end
|
130
190
|
|
131
191
|
def test_validate_fields_old_schema
|
@@ -140,14 +200,14 @@ class SchemacopValidatorTest < Minitest::Test
|
|
140
200
|
}
|
141
201
|
}
|
142
202
|
|
143
|
-
assert_schema
|
144
|
-
assert_schema
|
145
|
-
assert_schema
|
146
|
-
assert_schema
|
203
|
+
assert_schema(schema_rules, name: 'John', id: 2, ids: [1, 2, 3], currency: 'CHF')
|
204
|
+
assert_schema(schema_rules, name: nil, id: 2, ids: [1, 2, 3], currency: 'CHF')
|
205
|
+
assert_schema(schema_rules, name: nil, age: 2, id: 2, ids: nil, currency: 'CHF')
|
206
|
+
assert_schema(schema_rules, name: nil, id: 2, ids: nil, currency: 'CHF')
|
147
207
|
|
148
|
-
assert_schema_failure
|
149
|
-
assert_schema_failure
|
150
|
-
assert_schema_failure
|
208
|
+
assert_schema_failure(schema_rules, id: 2, ids: [1, 2, 3], currency: 'CHF')
|
209
|
+
assert_schema_failure(schema_rules, name: nil, id: nil, ids: [1, 2, 3], currency: 'CHF')
|
210
|
+
assert_schema_failure(schema_rules, name: nil, id: 2, ids: [1, 2, 3], currency: 'JPN')
|
151
211
|
end
|
152
212
|
|
153
213
|
def test_nested_old_schema
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemacop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- ".rubocop.yml"
|
148
148
|
- ".travis.yml"
|
149
149
|
- ".yardopts"
|
150
|
+
- CHANGELOG.md
|
150
151
|
- Gemfile
|
151
152
|
- LICENSE
|
152
153
|
- README.md
|