lutaml-model 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lutaml/model/validation.rb +3 -2
- data/lib/lutaml/model/version.rb +1 -1
- data/spec/lutaml/model/validation_spec.rb +53 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e9857c1f8a86d0fb3566c6d9e5e11723e203e7f58bd7fcfd3c5a0cb1702b6c
|
4
|
+
data.tar.gz: 270002530a82256d2682a060a9616320b76f9592aeb74d17451d26d311a45508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d98496343787aad60a34ee00c7df537b9fcd4160209cdd920d8265afdc048e7a26dbc3567b30ed1a5f5eb8120684b81dc9bb04a8964fd4495be67ae339bf5e
|
7
|
+
data.tar.gz: d51b92c1bda980ac8f30890236329880db515eb11e20e73a647dc78cdba2de58fc869d58a5905a20681f4b946dff205968f9f1cf619bac10aa677157497f05ff
|
@@ -6,13 +6,14 @@ module Lutaml
|
|
6
6
|
self.class.attributes.each do |name, attr|
|
7
7
|
value = public_send(:"#{name}")
|
8
8
|
begin
|
9
|
-
if value.respond_to?(:validate
|
10
|
-
value.validate
|
9
|
+
if value.respond_to?(:validate)
|
10
|
+
errors.concat(value.validate)
|
11
11
|
else
|
12
12
|
attr.validate_value!(value)
|
13
13
|
end
|
14
14
|
rescue Lutaml::Model::InvalidValueError,
|
15
15
|
Lutaml::Model::CollectionCountOutOfRangeError,
|
16
|
+
Lutaml::Model::CollectionTrueMissingError,
|
16
17
|
PatternNotMatchedError => e
|
17
18
|
errors << e
|
18
19
|
end
|
data/lib/lutaml/model/version.rb
CHANGED
@@ -12,6 +12,18 @@ RSpec.describe Lutaml::Model::Validation do
|
|
12
12
|
attribute :tags, :string, collection: true
|
13
13
|
attribute :role, :string, collection: 1..3
|
14
14
|
end)
|
15
|
+
|
16
|
+
stub_const("ValidationTestMainClass", Class.new(Lutaml::Model::Serializable) do
|
17
|
+
attribute :test_class, ValidationTestClass
|
18
|
+
|
19
|
+
xml do
|
20
|
+
map_element "test_class", to: :test_class
|
21
|
+
end
|
22
|
+
|
23
|
+
key_value do
|
24
|
+
map "test_class", to: :test_class
|
25
|
+
end
|
26
|
+
end)
|
15
27
|
end
|
16
28
|
|
17
29
|
let(:valid_instance) do
|
@@ -24,15 +36,29 @@ RSpec.describe Lutaml::Model::Validation do
|
|
24
36
|
)
|
25
37
|
end
|
26
38
|
|
39
|
+
let(:valid_nested_instance) do
|
40
|
+
ValidationTestMainClass.new(
|
41
|
+
test_class: valid_instance,
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
27
45
|
describe "#validate" do
|
28
46
|
it "returns an empty array for a valid instance" do
|
29
47
|
expect(valid_instance.validate).to be_empty
|
30
48
|
end
|
31
49
|
|
32
|
-
|
50
|
+
it "returns errors for invalid integer value" do
|
33
51
|
instance = ValidationTestClass.new(age: "thirty", role: ["admin"])
|
34
52
|
errors = instance.validate
|
35
|
-
expect(errors).to
|
53
|
+
expect(errors).to eq([])
|
54
|
+
expect(instance.age).to be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises error if Array is set but collection is not set" do
|
58
|
+
instance = ValidationTestClass.new(name: ["admin"])
|
59
|
+
expect do
|
60
|
+
instance.validate
|
61
|
+
end.not_to raise_error(Lutaml::Model::CollectionTrueMissingError)
|
36
62
|
end
|
37
63
|
|
38
64
|
it "returns errors for value not in allowed set" do
|
@@ -55,17 +81,20 @@ RSpec.describe Lutaml::Model::Validation do
|
|
55
81
|
end
|
56
82
|
end
|
57
83
|
|
58
|
-
|
84
|
+
it "returns multiple errors for multiple invalid attributes" do
|
59
85
|
instance = ValidationTestClass.new(name: "123", age: "thirty",
|
60
86
|
email: "invalid@example.com", role: [])
|
61
87
|
expect do
|
62
88
|
instance.validate!
|
63
89
|
end.to raise_error(Lutaml::Model::ValidationError) do |error|
|
64
|
-
expect(error.error_messages.join("\n")).to include("Invalid value for attribute age: thirty")
|
65
90
|
expect(error.error_messages.join("\n")).to include("email is `invalid@example.com`, must be one of the following [test@example.com, user@example.com]")
|
66
91
|
expect(error.error_messages.join("\n")).to include("role count is 0, must be between 1 and 3")
|
67
92
|
end
|
68
93
|
end
|
94
|
+
|
95
|
+
it "returns an empty array for a valid nested instance" do
|
96
|
+
expect(valid_nested_instance.validate).to be_empty
|
97
|
+
end
|
69
98
|
end
|
70
99
|
|
71
100
|
describe "#validate!" do
|
@@ -73,13 +102,31 @@ RSpec.describe Lutaml::Model::Validation do
|
|
73
102
|
expect { valid_instance.validate! }.not_to raise_error
|
74
103
|
end
|
75
104
|
|
76
|
-
|
105
|
+
it "raises a ValidationError with all error messages for an invalid instance" do
|
77
106
|
instance = ValidationTestClass.new(name: "test", age: "thirty")
|
78
107
|
expect do
|
79
108
|
instance.validate!
|
80
109
|
end.to raise_error(Lutaml::Model::ValidationError) do |error|
|
81
110
|
expect(error.error_messages.join("\n")).to include("role count is 0, must be between 1 and 3")
|
82
|
-
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it "validates nested ValidationTestClass instance" do
|
115
|
+
invalid_nested = ValidationTestMainClass.new(
|
116
|
+
test_class: ValidationTestClass.new(
|
117
|
+
name: "John Doe",
|
118
|
+
age: 30,
|
119
|
+
email: "invalid@example.com",
|
120
|
+
role: ["admin"],
|
121
|
+
),
|
122
|
+
)
|
123
|
+
|
124
|
+
expect do
|
125
|
+
invalid_nested.validate!
|
126
|
+
end.to raise_error(Lutaml::Model::ValidationError) do |error|
|
127
|
+
expect(error.error_messages.join("\n")).to include(
|
128
|
+
"email is `invalid@example.com`, must be one of the following [test@example.com, user@example.com]",
|
129
|
+
)
|
83
130
|
end
|
84
131
|
end
|
85
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lutaml-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|