lutaml-model 0.3.30 → 0.5.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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +34 -18
- data/README.adoc +172 -8
- data/lib/lutaml/model/attribute.rb +6 -2
- data/lib/lutaml/model/key_value_mapping.rb +0 -1
- data/lib/lutaml/model/key_value_mapping_rule.rb +3 -1
- data/lib/lutaml/model/mapping_rule.rb +14 -2
- data/lib/lutaml/model/serialize.rb +174 -61
- data/lib/lutaml/model/type/decimal.rb +5 -0
- data/lib/lutaml/model/type/time.rb +4 -4
- data/lib/lutaml/model/utils.rb +1 -1
- data/lib/lutaml/model/validation.rb +6 -2
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/builder/nokogiri.rb +1 -0
- data/lib/lutaml/model/xml_adapter/builder/oga.rb +180 -0
- data/lib/lutaml/model/xml_adapter/builder/ox.rb +1 -0
- data/lib/lutaml/model/xml_adapter/oga/document.rb +20 -0
- data/lib/lutaml/model/xml_adapter/oga/element.rb +117 -0
- data/lib/lutaml/model/xml_adapter/oga_adapter.rb +77 -44
- data/lib/lutaml/model/xml_adapter/xml_document.rb +11 -9
- data/lib/lutaml/model/xml_mapping.rb +0 -1
- data/lib/lutaml/model/xml_mapping_rule.rb +16 -4
- data/spec/address_spec.rb +1 -0
- data/spec/fixtures/sample_model.rb +7 -0
- data/spec/lutaml/model/custom_model_spec.rb +47 -1
- data/spec/lutaml/model/custom_serialization_spec.rb +16 -0
- data/spec/lutaml/model/enum_spec.rb +131 -0
- data/spec/lutaml/model/included_spec.rb +192 -0
- data/spec/lutaml/model/mixed_content_spec.rb +48 -32
- data/spec/lutaml/model/multiple_mapping_spec.rb +329 -0
- data/spec/lutaml/model/ordered_content_spec.rb +1 -1
- data/spec/lutaml/model/render_nil_spec.rb +3 -2
- data/spec/lutaml/model/serializable_spec.rb +3 -3
- data/spec/lutaml/model/type/boolean_spec.rb +62 -0
- data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +11 -11
- data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +1 -1
- data/spec/lutaml/model/xml_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_mapping_spec.rb +24 -9
- data/spec/sample_model_spec.rb +114 -0
- metadata +9 -2
@@ -0,0 +1,114 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "fixtures/sample_model"
|
3
|
+
|
4
|
+
RSpec.describe SampleModel do
|
5
|
+
let(:model) { described_class.new(attributes) }
|
6
|
+
let(:attributes_yaml) do
|
7
|
+
{
|
8
|
+
"name" => "John Doe",
|
9
|
+
"age" => 25,
|
10
|
+
"balance" => "100432423.523142344124",
|
11
|
+
"tags" => [
|
12
|
+
{ "text" => "ruby" },
|
13
|
+
{ "text" => "coding" },
|
14
|
+
],
|
15
|
+
"preferences" => { notifications: false, theme: "dark" },
|
16
|
+
"status" => "premium",
|
17
|
+
"large_number" => 9999,
|
18
|
+
"email" => "john@example.com",
|
19
|
+
"role" => "admin",
|
20
|
+
}
|
21
|
+
end
|
22
|
+
let(:attributes) do
|
23
|
+
{
|
24
|
+
name: "John Doe",
|
25
|
+
age: 25,
|
26
|
+
balance: BigDecimal("100432423.523142344124"),
|
27
|
+
tags: [
|
28
|
+
SampleModelTag.new(text: "ruby"),
|
29
|
+
SampleModelTag.new(text: "coding"),
|
30
|
+
],
|
31
|
+
preferences: { notifications: false, theme: "dark" },
|
32
|
+
status: "premium",
|
33
|
+
large_number: 9999,
|
34
|
+
email: "john@example.com",
|
35
|
+
role: "admin",
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "default values" do
|
40
|
+
let(:model) { described_class.new }
|
41
|
+
|
42
|
+
it "sets default name" do
|
43
|
+
expect(model.name).to eq("Anonymous")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "sets default age" do
|
47
|
+
expect(model.age).to eq(18)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "sets default balance" do
|
51
|
+
expect(model.balance).to eq(BigDecimal("0.0"))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sets default tags" do
|
55
|
+
expect(model.tags).to eq([])
|
56
|
+
end
|
57
|
+
|
58
|
+
it "sets default preferences" do
|
59
|
+
expect(model.preferences).to eq({ notifications: true })
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sets default status" do
|
63
|
+
expect(model.status).to eq("active")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets default large_number" do
|
67
|
+
expect(model.large_number).to eq(0)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "sets default email" do
|
71
|
+
expect(model.email).to eq("example@example.com")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "sets default role" do
|
75
|
+
expect(model.role).to eq("user")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "role validation" do
|
80
|
+
it "accepts valid roles" do
|
81
|
+
%w[user admin guest].each do |role|
|
82
|
+
model.role = role
|
83
|
+
expect(model.role).to eq(role)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "raises error for invalid role" do
|
88
|
+
model.role = "invalid"
|
89
|
+
expect { model.validate! }.to raise_error(Lutaml::Model::ValidationError)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "YAML serialization" do
|
94
|
+
it "serializes to YAML" do
|
95
|
+
expect(model.to_yaml).to eq(attributes_yaml.to_yaml)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "deserializes from YAML" do
|
99
|
+
yaml = attributes_yaml.to_yaml
|
100
|
+
sample = described_class.from_yaml(yaml)
|
101
|
+
|
102
|
+
expect(sample.name).to eq("John Doe")
|
103
|
+
expect(sample.age).to eq(25)
|
104
|
+
expect(sample.balance).to eq(BigDecimal("100432423.523142344124"))
|
105
|
+
expect(sample.tags).to all(be_a(SampleModelTag))
|
106
|
+
expect(sample.tags.map(&:text)).to eq(["ruby", "coding"])
|
107
|
+
expect(sample.preferences).to eq({ notifications: false, theme: "dark" })
|
108
|
+
expect(sample.status).to eq("premium")
|
109
|
+
expect(sample.large_number).to eq(9999)
|
110
|
+
expect(sample.email).to eq("john@example.com")
|
111
|
+
expect(sample.role).to eq("admin")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -107,8 +107,11 @@ files:
|
|
107
107
|
- lib/lutaml/model/version.rb
|
108
108
|
- lib/lutaml/model/xml_adapter.rb
|
109
109
|
- lib/lutaml/model/xml_adapter/builder/nokogiri.rb
|
110
|
+
- lib/lutaml/model/xml_adapter/builder/oga.rb
|
110
111
|
- lib/lutaml/model/xml_adapter/builder/ox.rb
|
111
112
|
- lib/lutaml/model/xml_adapter/nokogiri_adapter.rb
|
113
|
+
- lib/lutaml/model/xml_adapter/oga/document.rb
|
114
|
+
- lib/lutaml/model/xml_adapter/oga/element.rb
|
112
115
|
- lib/lutaml/model/xml_adapter/oga_adapter.rb
|
113
116
|
- lib/lutaml/model/xml_adapter/ox_adapter.rb
|
114
117
|
- lib/lutaml/model/xml_adapter/xml_attribute.rb
|
@@ -139,11 +142,14 @@ files:
|
|
139
142
|
- spec/lutaml/model/custom_serialization_spec.rb
|
140
143
|
- spec/lutaml/model/defaults_spec.rb
|
141
144
|
- spec/lutaml/model/delegation_spec.rb
|
145
|
+
- spec/lutaml/model/enum_spec.rb
|
146
|
+
- spec/lutaml/model/included_spec.rb
|
142
147
|
- spec/lutaml/model/inheritance_spec.rb
|
143
148
|
- spec/lutaml/model/json_adapter_spec.rb
|
144
149
|
- spec/lutaml/model/key_value_mapping_spec.rb
|
145
150
|
- spec/lutaml/model/map_content_spec.rb
|
146
151
|
- spec/lutaml/model/mixed_content_spec.rb
|
152
|
+
- spec/lutaml/model/multiple_mapping_spec.rb
|
147
153
|
- spec/lutaml/model/namespace_spec.rb
|
148
154
|
- spec/lutaml/model/ordered_content_spec.rb
|
149
155
|
- spec/lutaml/model/render_nil_spec.rb
|
@@ -178,6 +184,7 @@ files:
|
|
178
184
|
- spec/lutaml/model/yaml_adapter_spec.rb
|
179
185
|
- spec/lutaml/model_spec.rb
|
180
186
|
- spec/person_spec.rb
|
187
|
+
- spec/sample_model_spec.rb
|
181
188
|
- spec/spec_helper.rb
|
182
189
|
homepage: https://github.com/lutaml/lutaml-model
|
183
190
|
licenses:
|