schemacop 3.0.9 → 3.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +27 -0
- data/.releaser_config +0 -1
- data/CHANGELOG.md +17 -0
- data/README.md +1 -1
- data/README_V3.md +102 -43
- data/VERSION +1 -1
- data/lib/schemacop/v3/combination_node.rb +1 -1
- data/lib/schemacop/v3/node.rb +6 -5
- data/lib/schemacop/v3/one_of_node.rb +23 -1
- data/lib/schemacop/v3/string_node.rb +2 -2
- data/schemacop.gemspec +4 -4
- data/test/unit/schemacop/v3/array_node_test.rb +19 -17
- data/test/unit/schemacop/v3/boolean_node_test.rb +48 -8
- data/test/unit/schemacop/v3/hash_node_test.rb +49 -11
- data/test/unit/schemacop/v3/integer_node_test.rb +38 -14
- data/test/unit/schemacop/v3/node_test.rb +10 -0
- data/test/unit/schemacop/v3/number_node_test.rb +14 -9
- data/test/unit/schemacop/v3/object_node_test.rb +7 -7
- data/test/unit/schemacop/v3/one_of_node_test.rb +12 -0
- data/test/unit/schemacop/v3/reference_node_test.rb +4 -4
- data/test/unit/schemacop/v3/string_node_test.rb +13 -11
- data/test/unit/schemacop/v3/symbol_node_test.rb +9 -6
- metadata +3 -3
- data/.travis.yml +0 -9
@@ -3,7 +3,9 @@ require 'test_helper'
|
|
3
3
|
module Schemacop
|
4
4
|
module V3
|
5
5
|
class StringNodeTest < V3Test
|
6
|
-
|
6
|
+
def self.invalid_type_error(type)
|
7
|
+
"Invalid type, got type \"#{type}\", expected \"string\"."
|
8
|
+
end
|
7
9
|
|
8
10
|
def test_basic
|
9
11
|
schema :string
|
@@ -33,7 +35,7 @@ module Schemacop
|
|
33
35
|
assert_json(type: :string)
|
34
36
|
|
35
37
|
assert_validation 42 do
|
36
|
-
error '/',
|
38
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
37
39
|
end
|
38
40
|
|
39
41
|
schema { str! :name }
|
@@ -41,11 +43,11 @@ module Schemacop
|
|
41
43
|
assert_json(type: :object, properties: { name: { type: :string } }, required: %i[name], additionalProperties: false)
|
42
44
|
|
43
45
|
assert_validation name: :foo do
|
44
|
-
error '/name',
|
46
|
+
error '/name', StringNodeTest.invalid_type_error(Symbol)
|
45
47
|
end
|
46
48
|
|
47
49
|
assert_validation name: 234 do
|
48
|
-
error '/name',
|
50
|
+
error '/name', StringNodeTest.invalid_type_error(Integer)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -190,7 +192,7 @@ module Schemacop
|
|
190
192
|
assert_validation ''
|
191
193
|
|
192
194
|
assert_validation 234 do
|
193
|
-
error '/',
|
195
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
194
196
|
end
|
195
197
|
|
196
198
|
assert_cast(nil, nil)
|
@@ -218,7 +220,7 @@ module Schemacop
|
|
218
220
|
# Integer value 42 is in the enum of allowed values, but it's not a string,
|
219
221
|
# so the validation still fails
|
220
222
|
assert_validation 42 do
|
221
|
-
error '/',
|
223
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
222
224
|
end
|
223
225
|
end
|
224
226
|
|
@@ -278,7 +280,7 @@ module Schemacop
|
|
278
280
|
assert_validation(nil)
|
279
281
|
assert_validation('Foo')
|
280
282
|
assert_validation(5) do
|
281
|
-
error '/',
|
283
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
282
284
|
end
|
283
285
|
|
284
286
|
assert_cast('Foo', 'Foo')
|
@@ -297,7 +299,7 @@ module Schemacop
|
|
297
299
|
assert_validation(nil)
|
298
300
|
assert_validation('123')
|
299
301
|
assert_validation(5) do
|
300
|
-
error '/',
|
302
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
301
303
|
end
|
302
304
|
|
303
305
|
assert_cast('123', 123)
|
@@ -364,13 +366,13 @@ module Schemacop
|
|
364
366
|
# Even we put those types in the enum, they need to fail the validations,
|
365
367
|
# as they are not strings
|
366
368
|
assert_validation(1) do
|
367
|
-
error '/',
|
369
|
+
error '/', StringNodeTest.invalid_type_error(Integer)
|
368
370
|
end
|
369
371
|
assert_validation(:bar) do
|
370
|
-
error '/',
|
372
|
+
error '/', StringNodeTest.invalid_type_error(Symbol)
|
371
373
|
end
|
372
374
|
assert_validation({ qux: 42 }) do
|
373
|
-
error '/',
|
375
|
+
error '/', StringNodeTest.invalid_type_error(Hash)
|
374
376
|
end
|
375
377
|
|
376
378
|
# These need to fail validation, as they are not in the enum list
|
@@ -3,7 +3,10 @@ require 'test_helper'
|
|
3
3
|
module Schemacop
|
4
4
|
module V3
|
5
5
|
class SymbolNodeTest < V3Test
|
6
|
-
|
6
|
+
def self.invalid_type_error(type)
|
7
|
+
type = type.class unless type.class == Class
|
8
|
+
"Invalid type, got type \"#{type}\", expected \"Symbol\"."
|
9
|
+
end
|
7
10
|
|
8
11
|
def test_basic
|
9
12
|
schema :symbol
|
@@ -11,10 +14,10 @@ module Schemacop
|
|
11
14
|
assert_validation :foo
|
12
15
|
assert_validation :'n0238n)Q(hqr3hrw3'
|
13
16
|
assert_validation 42 do
|
14
|
-
error '/',
|
17
|
+
error '/', SymbolNodeTest.invalid_type_error(Integer)
|
15
18
|
end
|
16
19
|
assert_validation '42' do
|
17
|
-
error '/',
|
20
|
+
error '/', SymbolNodeTest.invalid_type_error(String)
|
18
21
|
end
|
19
22
|
assert_json({})
|
20
23
|
end
|
@@ -56,13 +59,13 @@ module Schemacop
|
|
56
59
|
# Even we put those types in the enum, they need to fail the validations,
|
57
60
|
# as they are not symbols
|
58
61
|
assert_validation('foo') do
|
59
|
-
error '/',
|
62
|
+
error '/', SymbolNodeTest.invalid_type_error(String)
|
60
63
|
end
|
61
64
|
assert_validation(1) do
|
62
|
-
error '/',
|
65
|
+
error '/', SymbolNodeTest.invalid_type_error(Integer)
|
63
66
|
end
|
64
67
|
assert_validation({ qux: 42 }) do
|
65
|
-
error '/',
|
68
|
+
error '/', SymbolNodeTest.invalid_type_error(Hash)
|
66
69
|
end
|
67
70
|
|
68
71
|
# These need to fail validation, as they are not in the enum list
|
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: 3.0.
|
4
|
+
version: 3.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -170,10 +170,10 @@ executables: []
|
|
170
170
|
extensions: []
|
171
171
|
extra_rdoc_files: []
|
172
172
|
files:
|
173
|
+
- ".github/workflows/ruby.yml"
|
173
174
|
- ".gitignore"
|
174
175
|
- ".releaser_config"
|
175
176
|
- ".rubocop.yml"
|
176
|
-
- ".travis.yml"
|
177
177
|
- ".yardopts"
|
178
178
|
- CHANGELOG.md
|
179
179
|
- Gemfile
|