lutaml-model 0.3.29 → 0.3.30

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fba70c8a3fca206b3109603109812019773027580c47b2e3615d873df6e0ce2d
4
- data.tar.gz: 21313fbfb52c29c620eb1020672d337689eed963c25fe56c20baeef139e569b5
3
+ metadata.gz: cca2f0b92a3e71807ed2201909e02ea5877dc1468c34c62d887d523962e63968
4
+ data.tar.gz: 56fe25dc8f9229d2bcabe1315c88f0f7d8fb3a3ca5f01b78b0e6494fb65ebc75
5
5
  SHA512:
6
- metadata.gz: 274739542b8473ae58b4fc6b78e1152aaef604a55f3c9db0ec5678743573d683b4afdd2429d97d6a24c03fdb2c14a72904bf4e057f480e6bafc635a21fde085a
7
- data.tar.gz: b1a7ad49313463676b3afe8732f94ed8ab37f79935f33449c70011bd8a8449934425aa27b9dd25d2a7e25a064afa1e665bf95f8b2eac4ec7cd63be4bcfdb7b8d
6
+ metadata.gz: a6d19950a00e397146f8a8cfc8eeeb0e3c965f9fb7f5cb3bb5518cf636505f31ec72750552385b533d410eec51c6e325d0d57070fca52189ff00a48c8380c156
7
+ data.tar.gz: b7d55249da057ffe7f222c997ae4f628c7dd5acdeee9d7a1a5919f7f6d034ac5342b961696797029233dcd931a7db82be67f00f89a5b78463c3a7c101fbc3e4f
@@ -0,0 +1,15 @@
1
+ {
2
+ "repo": [
3
+ "lutaml/genericode",
4
+ "lutaml/ogc-gml",
5
+ "metanorma/modspec-ruby",
6
+ "metanorma/rfcxml",
7
+ "metanorma/niso-jats",
8
+ "metanorma/sts-ruby",
9
+ "lutaml/metaschema",
10
+ "glossarist/termium",
11
+ "lutaml/oasis-etm",
12
+ "lutaml/ali",
13
+ "lutaml/reqif"
14
+ ]
15
+ }
@@ -0,0 +1,14 @@
1
+ name: dependent-gems-test
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ tags: [ v* ]
7
+ pull_request:
8
+ workflow_dispatch:
9
+ repository_dispatch:
10
+ types: [ release-passed ]
11
+
12
+ jobs:
13
+ rake:
14
+ uses: metanorma/ci/.github/workflows/dependent-rake.yml@main
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2024-11-25 13:01:09 UTC using RuboCop version 1.66.1.
3
+ # on 2024-12-03 11:13:42 UTC using RuboCop version 1.66.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 185
9
+ # Offense count: 224
10
10
  # This cop supports safe autocorrection (--autocorrect).
11
11
  # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
12
12
  # URISchemes: http, https
@@ -51,7 +51,7 @@ Metrics/AbcSize:
51
51
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
52
52
  # AllowedMethods: refine
53
53
  Metrics/BlockLength:
54
- Max: 47
54
+ Max: 46
55
55
 
56
56
  # Offense count: 28
57
57
  # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
@@ -65,7 +65,7 @@ Metrics/CyclomaticComplexity:
65
65
  - 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
66
66
  - 'lib/lutaml/model/xml_adapter/xml_document.rb'
67
67
 
68
- # Offense count: 55
68
+ # Offense count: 54
69
69
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
70
70
  Metrics/MethodLength:
71
71
  Max: 46
@@ -97,7 +97,15 @@ RSpec/ContextWording:
97
97
  - 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
98
98
  - 'spec/lutaml/model/xml_mapping_spec.rb'
99
99
 
100
- # Offense count: 127
100
+ # Offense count: 1
101
+ # This cop supports unsafe autocorrection (--autocorrect-all).
102
+ # Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
103
+ # SupportedStyles: described_class, explicit
104
+ RSpec/DescribedClass:
105
+ Exclude:
106
+ - 'spec/lutaml/model/xml_mapping_spec.rb'
107
+
108
+ # Offense count: 133
101
109
  # Configuration parameters: CountAsOne.
102
110
  RSpec/ExampleLength:
103
111
  Max: 54
@@ -127,7 +135,7 @@ RSpec/MultipleDescribes:
127
135
  - 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
128
136
  - 'spec/lutaml/model/xml_adapter_spec.rb'
129
137
 
130
- # Offense count: 153
138
+ # Offense count: 157
131
139
  RSpec/MultipleExpectations:
132
140
  Max: 14
133
141
 
@@ -136,7 +144,7 @@ RSpec/MultipleExpectations:
136
144
  RSpec/MultipleMemoizedHelpers:
137
145
  Max: 9
138
146
 
139
- # Offense count: 11
147
+ # Offense count: 15
140
148
  # Configuration parameters: AllowedGroups.
141
149
  RSpec/NestedGroups:
142
150
  Max: 4
@@ -7,7 +7,7 @@ module Lutaml
7
7
  module JsonAdapter
8
8
  # Base class for JSON documents
9
9
  class JsonDocument < JsonObject
10
- def self.parse(json)
10
+ def self.parse(json, _options = {})
11
11
  raise NotImplementedError, "Subclasses must implement `parse`."
12
12
  end
13
13
 
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module JsonAdapter
7
7
  class MultiJsonAdapter < JsonDocument
8
- def self.parse(json)
8
+ def self.parse(json, _options = {})
9
9
  data = MultiJson.load(json)
10
10
  new(data)
11
11
  end
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module JsonAdapter
7
7
  class StandardJsonAdapter < JsonDocument
8
- def self.parse(json)
8
+ def self.parse(json, _options = {})
9
9
  JSON.parse(json, create_additions: false)
10
10
  end
11
11
 
@@ -51,6 +51,7 @@ module Lutaml
51
51
  Utils.add_boolean_accessor_if_not_defined(klass, :ordered)
52
52
  Utils.add_boolean_accessor_if_not_defined(klass, :mixed)
53
53
  Utils.add_accessor_if_not_defined(klass, :element_order)
54
+ Utils.add_accessor_if_not_defined(klass, :encoding)
54
55
 
55
56
  Utils.add_method_if_not_defined(klass,
56
57
  :using_default_for) do |attribute_name|
@@ -101,23 +102,22 @@ module Lutaml
101
102
  end
102
103
  end
103
104
 
104
- define_method(:"from_#{format}") do |data|
105
+ define_method(:"from_#{format}") do |data, options = {}|
105
106
  adapter = Lutaml::Model::Config.send(:"#{format}_adapter")
106
107
 
107
- doc = adapter.parse(data)
108
- public_send(:"of_#{format}", doc)
108
+ doc = adapter.parse(data, options)
109
+ public_send(:"of_#{format}", doc, options)
109
110
  end
110
111
 
111
- define_method(:"of_#{format}") do |doc|
112
+ define_method(:"of_#{format}") do |doc, options = {}|
112
113
  if doc.is_a?(Array)
113
- return doc.map do |item|
114
- send(:"of_#{format}", item)
115
- end
114
+ return doc.map { |item| send(:"of_#{format}", item) }
116
115
  end
117
116
 
118
117
  if format == :xml
119
118
  doc_hash = doc.parse_element(doc.root, self, :xml)
120
- apply_mappings(doc_hash, format)
119
+ options[:encoding] = doc.encoding
120
+ apply_mappings(doc_hash, format, options)
121
121
  else
122
122
  apply_mappings(doc.to_h, format)
123
123
  end
@@ -315,6 +315,7 @@ module Lutaml
315
315
  end
316
316
 
317
317
  def apply_xml_mapping(doc, instance, options = {})
318
+ instance.encoding = options[:encoding]
318
319
  return instance unless doc
319
320
 
320
321
  if options[:default_namespace].nil?
@@ -347,6 +348,8 @@ module Lutaml
347
348
  mappings.each do |rule|
348
349
  raise "Attribute '#{rule.to}' not found in #{self}" unless valid_rule?(rule)
349
350
 
351
+ attr = attribute_for_rule(rule)
352
+
350
353
  value = if rule.raw_mapping?
351
354
  doc.node.inner_xml
352
355
  elsif rule.content_mapping?
@@ -355,10 +358,10 @@ module Lutaml
355
358
  doc.fetch(rule.namespaced_name(options[:default_namespace]))
356
359
  else
357
360
  defaults_used << rule.to
358
- rule.to_value_for(instance)
361
+ attr&.default || rule.to_value_for(instance)
359
362
  end
360
363
 
361
- value = normalize_xml_value(value, rule, options)
364
+ value = normalize_xml_value(value, rule, attr, options)
362
365
  rule.deserialize(instance, value, attributes, self)
363
366
  end
364
367
 
@@ -399,9 +402,7 @@ module Lutaml
399
402
  instance
400
403
  end
401
404
 
402
- def normalize_xml_value(value, rule, options = {})
403
- attr = attribute_for_rule(rule)
404
-
405
+ def normalize_xml_value(value, rule, attr, options = {})
405
406
  value = [value].compact if attr&.collection? && !value.is_a?(Array)
406
407
 
407
408
  value = if value.is_a?(Array)
@@ -459,7 +460,7 @@ module Lutaml
459
460
  end
460
461
  end
461
462
 
462
- attr_accessor :element_order, :schema_location
463
+ attr_accessor :element_order, :schema_location, :encoding
463
464
  attr_writer :ordered, :mixed
464
465
 
465
466
  def initialize(attrs = {})
@@ -548,6 +549,7 @@ module Lutaml
548
549
  options)
549
550
  end
550
551
 
552
+ options[:parse_encoding] = encoding if encoding
551
553
  adapter.new(representation).public_send(:"to_#{format}", options)
552
554
  end
553
555
  end
@@ -7,7 +7,7 @@ module Lutaml
7
7
  module TomlAdapter
8
8
  # Base class for TOML documents
9
9
  class TomlDocument < TomlObject
10
- def self.parse(toml)
10
+ def self.parse(toml, _options = {})
11
11
  raise NotImplementedError, "Subclasses must implement `parse`."
12
12
  end
13
13
 
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module TomlAdapter
7
7
  class TomlRbAdapter < TomlDocument
8
- def self.parse(toml)
8
+ def self.parse(toml, _options = {})
9
9
  data = TomlRB.parse(toml)
10
10
  new(data)
11
11
  end
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module TomlAdapter
7
7
  class TomlibAdapter < TomlDocument
8
- def self.parse(toml)
8
+ def self.parse(toml, _options = {})
9
9
  data = Tomlib.load(toml)
10
10
  new(data)
11
11
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.3.29"
5
+ VERSION = "0.3.30"
6
6
  end
7
7
  end
@@ -51,6 +51,16 @@ module Lutaml
51
51
  end
52
52
  end
53
53
 
54
+ def add_xml_fragment(element, content)
55
+ if element.is_a?(self.class)
56
+ element = element.xml.parent
57
+ end
58
+
59
+ fragment = ::Nokogiri::XML::DocumentFragment.parse(content)
60
+
61
+ element.add_child(fragment)
62
+ end
63
+
54
64
  def add_text(element, text, cdata: false)
55
65
  return add_cdata(element, text) if cdata
56
66
 
@@ -66,10 +66,14 @@ module Lutaml
66
66
  xml.text(text)
67
67
  end
68
68
 
69
+ def add_xml_fragment(element, content)
70
+ element.raw(content)
71
+ end
72
+
69
73
  def add_text(element, text, cdata: false)
70
74
  return element.cdata(text) if cdata
71
75
 
72
- element << text
76
+ element.text(text)
73
77
  end
74
78
 
75
79
  def add_cdata(element, value)
@@ -6,10 +6,10 @@ module Lutaml
6
6
  module Model
7
7
  module XmlAdapter
8
8
  class NokogiriAdapter < XmlDocument
9
- def self.parse(xml)
10
- parsed = Nokogiri::XML(xml)
9
+ def self.parse(xml, options = {})
10
+ parsed = Nokogiri::XML(xml, nil, options[:encoding])
11
11
  root = NokogiriElement.new(parsed.root)
12
- new(root)
12
+ new(root, parsed.encoding)
13
13
  end
14
14
 
15
15
  def to_xml(options = {})
@@ -17,6 +17,8 @@ module Lutaml
17
17
 
18
18
  if options.key?(:encoding)
19
19
  builder_options[:encoding] = options[:encoding] unless options[:encoding].nil?
20
+ elsif options.key?(:parse_encoding)
21
+ builder_options[:encoding] = options[:parse_encoding]
20
22
  else
21
23
  builder_options[:encoding] = "UTF-8"
22
24
  end
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module XmlAdapter
7
7
  class OgaAdapter < XmlDocument
8
- def self.parse(xml)
8
+ def self.parse(xml, _options = {})
9
9
  parsed = Oga.parse_xml(xml)
10
10
  root = OgaElement.new(parsed)
11
11
  new(root)
@@ -6,23 +6,28 @@ module Lutaml
6
6
  module Model
7
7
  module XmlAdapter
8
8
  class OxAdapter < XmlDocument
9
- def self.parse(xml)
9
+ def self.parse(xml, options = {})
10
+ Ox.default_options = Ox.default_options.merge(encoding: options[:encoding] || "UTF-8")
11
+
10
12
  parsed = Ox.parse(xml)
11
13
  root = OxElement.new(parsed)
12
- new(root)
14
+ new(root, Ox.default_options[:encoding])
13
15
  end
14
16
 
15
17
  def to_xml(options = {})
16
- builder = Builder::Ox.build
17
18
  builder_options = { version: options[:version] }
18
19
 
19
- if options.key?(:encoding)
20
- builder_options[:encoding] = options[:encoding] unless options[:encoding].nil?
21
- else
22
- builder_options[:encoding] = "UTF-8"
23
- end
20
+ builder_options[:encoding] = if options.key?(:encoding)
21
+ options[:encoding]
22
+ elsif options.key?(:parse_encoding)
23
+ options[:parse_encoding]
24
+ else
25
+ "UTF-8"
26
+ end
27
+
28
+ builder = Builder::Ox.build
29
+ builder.xml.instruct(:xml, encoding: options[:parse_encoding])
24
30
 
25
- builder.xml.instruct(:xml, builder_options)
26
31
  if @root.is_a?(Lutaml::Model::XmlAdapter::OxElement)
27
32
  @root.build_xml(builder)
28
33
  elsif ordered?(@root, options)
@@ -34,7 +39,12 @@ module Lutaml
34
39
  end
35
40
 
36
41
  xml_data = builder.xml.to_s
37
- options[:declaration] ? xml_data : xml_data.sub(/\A<\?xml[^>]*\?>\n?/, "")
42
+ if builder_options[:encoding] && xml_data.valid_encoding?
43
+ xml_data = xml_data.encode(builder_options[:encoding])
44
+ end
45
+
46
+ stripped_data = xml_data.lines.drop(1).join
47
+ options[:declaration] ? declaration(options) + stripped_data : stripped_data
38
48
  end
39
49
 
40
50
  private
@@ -145,6 +155,11 @@ module Lutaml
145
155
  build_xml.xml.to_s
146
156
  end
147
157
 
158
+ def inner_xml
159
+ # Ox builder by default, adds a newline at the end, so `chomp` is used
160
+ children.map { |child| child.to_xml.chomp }.join
161
+ end
162
+
148
163
  def build_xml(builder = nil)
149
164
  builder ||= Builder::Ox.build
150
165
  attrs = build_attributes(self)
@@ -7,13 +7,14 @@ module Lutaml
7
7
  module Model
8
8
  module XmlAdapter
9
9
  class XmlDocument
10
- attr_reader :root
10
+ attr_reader :root, :encoding
11
11
 
12
- def initialize(root)
12
+ def initialize(root, encoding = nil)
13
13
  @root = root
14
+ @encoding = encoding
14
15
  end
15
16
 
16
- def self.parse(xml)
17
+ def self.parse(xml, _options = {})
17
18
  raise NotImplementedError, "Subclasses must implement `parse`."
18
19
  end
19
20
 
@@ -150,6 +151,8 @@ module Lutaml
150
151
  value,
151
152
  options.merge({ rule: rule, attribute: attribute }),
152
153
  )
154
+ elsif rule.raw_mapping?
155
+ xml.add_xml_fragment(xml, value)
153
156
  elsif rule.prefix_set?
154
157
  xml.create_and_add_element(rule.name, prefix: prefix) do
155
158
  add_value(xml, value, attribute, cdata: rule.cdata)
@@ -186,10 +189,6 @@ module Lutaml
186
189
  attributes = build_attributes(element,
187
190
  xml_mapping, options).merge(attributes)&.compact
188
191
 
189
- if element.respond_to?(:schema_location) && element.schema_location
190
- attributes.merge!(element.schema_location.to_xml_attributes)
191
- end
192
-
193
192
  prefix = if options.key?(:namespace_prefix)
194
193
  options[:namespace_prefix]
195
194
  elsif xml_mapping.namespace_prefix
@@ -210,7 +209,8 @@ module Lutaml
210
209
  xml)
211
210
  end
212
211
 
213
- xml_mapping.elements.each do |element_rule|
212
+ mappings = xml_mapping.elements + [xml_mapping.raw_mapping].compact
213
+ mappings.each do |element_rule|
214
214
  attribute_def = attribute_definition_for(element, element_rule,
215
215
  mapper_class: mapper_class)
216
216
 
@@ -234,20 +234,9 @@ module Lutaml
234
234
 
235
235
  process_content_mapping(element, xml_mapping.content_mapping,
236
236
  prefixed_xml)
237
-
238
- process_raw_mapping(element, xml_mapping.raw_mapping, prefixed_xml)
239
237
  end
240
238
  end
241
239
 
242
- def process_raw_mapping(element, rule, xml)
243
- return unless rule
244
-
245
- value = attribute_value_for(element, rule)
246
- return unless render_element?(rule, element, value)
247
-
248
- xml.add_text(xml, value, cdata: rule.cdata)
249
- end
250
-
251
240
  def process_content_mapping(element, content_rule, xml)
252
241
  return unless content_rule
253
242
 
@@ -343,7 +332,7 @@ module Lutaml
343
332
  {}
344
333
  end
345
334
 
346
- if element.respond_to?(:schema_location) && element.schema_location
335
+ if element.respond_to?(:schema_location) && element.schema_location && !options[:except]&.include?(:schema_location)
347
336
  attrs.merge!(element.schema_location.to_xml_attributes)
348
337
  end
349
338
 
@@ -355,10 +344,9 @@ module Lutaml
355
344
  hash["xmlns:#{mapping_rule.prefix}"] = mapping_rule.namespace
356
345
  end
357
346
 
358
- if render_element?(mapping_rule, element,
359
- mapping_rule.to_value_for(element))
360
- hash[mapping_rule.prefixed_name] =
361
- mapping_rule.to_value_for(element)
347
+ value = mapping_rule.to_value_for(element)
348
+ if render_element?(mapping_rule, element, value)
349
+ hash[mapping_rule.prefixed_name] = value ? value.to_s : value
362
350
  end
363
351
  end
364
352
 
@@ -14,7 +14,7 @@ module Lutaml
14
14
  PERMITTED_CLASSES_BASE
15
15
  end.freeze
16
16
 
17
- def self.parse(yaml)
17
+ def self.parse(yaml, _options = {})
18
18
  YAML.safe_load(yaml, permitted_classes: PERMITTED_CLASSES)
19
19
  end
20
20
 
@@ -7,7 +7,7 @@ module Lutaml
7
7
  module YamlAdapter
8
8
  # Base class for YAML documents
9
9
  class YamlDocument < YamlObject
10
- def self.parse(yaml)
10
+ def self.parse(yaml, _options = {})
11
11
  raise NotImplementedError, "Subclasses must implement `parse`."
12
12
  end
13
13
 
@@ -0,0 +1,5 @@
1
+ <note>
2
+ <to>Jos�</to>
3
+ <from>M�ller</from>
4
+ <heading>Reminder</heading>
5
+ </note>
@@ -0,0 +1,4 @@
1
+ <root>
2
+ <FieldName>�菑���p���P</FieldName>
3
+ <FieldName>123456</FieldName>
4
+ </root>
@@ -105,6 +105,29 @@ module DefaultsSpec
105
105
  map "opacity", to: :opacity, render_default: false
106
106
  end
107
107
  end
108
+
109
+ # Class for testing render_default: true with custom model
110
+ class Lang
111
+ attr_accessor :lang, :content
112
+ end
113
+
114
+ class CustomModelWithDefaultValue < Lutaml::Model::Serializable
115
+ model Lang
116
+
117
+ attribute :lang, :string, default: -> { "en" }
118
+ attribute :content, :string, default: -> { "default value not render when render_default is false" }
119
+
120
+ xml do
121
+ root "CustomModelWithDefaultValue"
122
+ map_attribute "lang", to: :lang, render_default: true
123
+ map_content to: :content, render_default: false
124
+ end
125
+
126
+ key_value do
127
+ map "lang", to: :lang, render_default: true
128
+ map "content", to: :content, render_default: false
129
+ end
130
+ end
108
131
  end
109
132
 
110
133
  RSpec.describe DefaultsSpec::Glaze do
@@ -125,6 +148,13 @@ RSpec.describe DefaultsSpec::Glaze do
125
148
  expect(default_model.manufacturer).to eq("example@glazes.com")
126
149
  expect(default_model.type).to eq("stoneware")
127
150
  end
151
+
152
+ it "contains the default value in instance" do
153
+ instance = DefaultsSpec::CustomModelWithDefaultValue.new
154
+
155
+ expect(instance.content).to eq("default value not render when render_default is false")
156
+ expect(instance.lang).to eq("en")
157
+ end
128
158
  end
129
159
 
130
160
  describe "Default value rendering behavior" do
@@ -155,6 +185,15 @@ RSpec.describe DefaultsSpec::Glaze do
155
185
  expect(xml).to include("<Opacity>Opaque</Opacity>")
156
186
  expect(xml).to include("<FiringTime>60</FiringTime>")
157
187
  end
188
+
189
+ it "serializes when render_default is true with custom model" do
190
+ parsed = DefaultsSpec::CustomModelWithDefaultValue.from_xml "<CustomModelWithDefaultValue>English</CustomModelWithDefaultValue>"
191
+ expect(parsed.lang).to eq("en")
192
+ expect(parsed.content).to eq("English")
193
+
194
+ serialized = DefaultsSpec::CustomModelWithDefaultValue.to_xml(parsed)
195
+ expect(serialized).to eq("<CustomModelWithDefaultValue lang=\"en\">English</CustomModelWithDefaultValue>")
196
+ end
158
197
  end
159
198
 
160
199
  context "when value is not default" do
@@ -200,6 +239,15 @@ RSpec.describe DefaultsSpec::Glaze do
200
239
  expect(json["opacity"]).to eq("Opaque")
201
240
  expect(json["firingTime"]).to eq(60)
202
241
  end
242
+
243
+ it "serializes when render_default is true with custom model" do
244
+ parsed = DefaultsSpec::CustomModelWithDefaultValue.from_json('{"content": "content"}')
245
+ expect(parsed.lang).to eq("en")
246
+ expect(parsed.content).to eq("content")
247
+
248
+ serialized = DefaultsSpec::CustomModelWithDefaultValue.to_json(parsed)
249
+ expect(serialized).to eq('{"lang":"en","content":"content"}')
250
+ end
203
251
  end
204
252
 
205
253
  context "when value is not default" do
@@ -217,5 +265,31 @@ RSpec.describe DefaultsSpec::Glaze do
217
265
  end
218
266
  end
219
267
  end
268
+
269
+ context "with YAML serialization" do
270
+ context "when value is default" do
271
+ it "serializes when render_default is true with custom model" do
272
+ parsed = DefaultsSpec::CustomModelWithDefaultValue.from_yaml("---\ncontent: content")
273
+ expect(parsed.lang).to eq("en")
274
+ expect(parsed.content).to eq("content")
275
+
276
+ serialized = DefaultsSpec::CustomModelWithDefaultValue.to_yaml(parsed)
277
+ expect(serialized).to eq("---\nlang: en\ncontent: content\n")
278
+ end
279
+ end
280
+ end
281
+
282
+ context "with TOML serialization" do
283
+ context "when value is default" do
284
+ it "serializes when render_default is true with custom model" do
285
+ parsed = DefaultsSpec::CustomModelWithDefaultValue.from_toml("content = 'content'")
286
+ expect(parsed.lang).to eq("en")
287
+ expect(parsed.content).to eq("content")
288
+
289
+ serialized = DefaultsSpec::CustomModelWithDefaultValue.to_toml(parsed)
290
+ expect(serialized).to eq("content = \"content\"\nlang = \"en\"\n")
291
+ end
292
+ end
293
+ end
220
294
  end
221
295
  end