lutaml-model 0.8.192 → 0.8.193

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.
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "tmpdir"
5
+ require "securerandom"
6
+
7
+ # When a Serializable declares an attribute with a string type that points
8
+ # into a namespace using autoload + lazy per-file registration, resolving
9
+ # just the leaf constant via const_get leaves sibling types unregistered.
10
+ # Deserialization of the root then fails because child element types are
11
+ # missing from the registry.
12
+ #
13
+ # The fix in `Lutaml::Model::Attribute.cast_from_string!` walks each parent
14
+ # namespace segment of the string type and force-resolves its constants so
15
+ # autoloads fire and per-file registration side-effects complete.
16
+
17
+ RSpec.describe "string-type resolution with namespace autoload" do
18
+ # Build a throwaway namespace with autoloads pointing at files that
19
+ # self-register on load. This mirrors the pattern used by gems like
20
+ # `mml` (where each `lib/mml/v3/<tag>.rb` ends with
21
+ # `Configuration.register_model(...)`).
22
+ def build_namespace(name)
23
+ Object.const_set(name, Module.new)
24
+
25
+ ns = Object.const_get(name)
26
+ ns.const_set(:REGISTRY, {})
27
+ ns.const_set(:LOADED_FILES, [])
28
+ ns.singleton_class.define_method(:loaded_files) { ns::LOADED_FILES }
29
+ ns.singleton_class.define_method(:registry) { ns::REGISTRY }
30
+
31
+ tmpdir = Dir.mktmpdir("lutaml-autoload-#{name.downcase}")
32
+
33
+ root_file = File.join(tmpdir, "root.rb")
34
+ sibling_file = File.join(tmpdir, "sibling.rb")
35
+
36
+ File.write(root_file, <<~RUBY)
37
+ #{name}::LOADED_FILES << "root"
38
+ #{name}::REGISTRY[:root] = Class.new
39
+ #{name}.const_set(:Root, #{name}::REGISTRY[:root])
40
+ RUBY
41
+
42
+ File.write(sibling_file, <<~RUBY)
43
+ #{name}::LOADED_FILES << "sibling"
44
+ #{name}::REGISTRY[:sibling] = Class.new
45
+ #{name}.const_set(:Sibling, #{name}::REGISTRY[:sibling])
46
+ RUBY
47
+
48
+ ns.autoload(:Root, root_file)
49
+ ns.autoload(:Sibling, sibling_file)
50
+ ns
51
+ end
52
+
53
+ # Each spec builds a uniquely-named namespace (via SecureRandom), so
54
+ # cross-test cleanup is unnecessary. Constants leak for the duration of
55
+ # the process but never collide.
56
+
57
+ let(:namespace_name) { :"LutamlAutoloadTest#{SecureRandom.hex(4)}" }
58
+ let(:namespace_module) { Object.const_get(namespace_name) }
59
+
60
+ it "eager-resolves sibling autoloads when a namespaced string type is cast" do
61
+ build_namespace(namespace_name)
62
+ expect(namespace_module.loaded_files).to be_empty
63
+
64
+ Lutaml::Model::Attribute.cast_from_string!("#{namespace_module}::Root")
65
+
66
+ expect(namespace_module.loaded_files).to include("root", "sibling")
67
+ expect(namespace_module.registry.key?(:root)).to be(true)
68
+ expect(namespace_module.registry.key?(:sibling)).to be(true)
69
+ end
70
+
71
+ it "is idempotent across multiple cast_from_string! calls within the same namespace" do
72
+ build_namespace(namespace_name)
73
+
74
+ Lutaml::Model::Attribute.cast_from_string!("#{namespace_module}::Root")
75
+ first_count = namespace_module.loaded_files.length
76
+
77
+ Lutaml::Model::Attribute.cast_from_string!("#{namespace_module}::Sibling")
78
+ expect(namespace_module.loaded_files.length).to eq(first_count)
79
+ end
80
+
81
+ it "raises ArgumentError for unknown types" do
82
+ expect do
83
+ Lutaml::Model::Attribute.cast_from_string!("LutamlAutoloadDoesNotExist::X")
84
+ end.to raise_error(ArgumentError, /Unknown Lutaml::Model::Type/)
85
+ end
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.192
4
+ version: 0.8.193
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -246,6 +246,7 @@ files:
246
246
  - docs/_guides/turtle-serialization.adoc
247
247
  - docs/_guides/type-registers-contexts.adoc
248
248
  - docs/_guides/value-transformations.adoc
249
+ - docs/_guides/xml-guide-0.8.0.adoc
249
250
  - docs/_guides/xml-mapping.adoc
250
251
  - docs/_guides/xml-mappings-guide.adoc
251
252
  - docs/_guides/xml-namespace-declarations.adoc
@@ -322,9 +323,16 @@ files:
322
323
  - docs/conversion_caching.adoc
323
324
  - docs/index.adoc
324
325
  - docs/key_value_data_model.adoc
326
+ - docs/missing_xml_features.adoc
325
327
  - docs/model_transforms.adoc
326
328
  - docs/namespace-management.adoc
327
329
  - docs/xml-schema-qualification.md
330
+ - docs/xml_1.0.adoc
331
+ - docs/xml_base.adoc
332
+ - docs/xml_data_types.adoc
333
+ - docs/xml_namespace.adoc
334
+ - docs/xml_schema.adoc
335
+ - docs/xml_xlink.adoc
328
336
  - docs/yamls_sequence.adoc
329
337
  - exe/lutaml-lml-lsp
330
338
  - exe/lutaml-model
@@ -2116,6 +2124,7 @@ files:
2116
2124
  - spec/lutaml/model/model_import_reentry_spec.rb
2117
2125
  - spec/lutaml/model/model_transformer_spec.rb
2118
2126
  - spec/lutaml/model/multiple_mapping_spec.rb
2127
+ - spec/lutaml/model/namespace_autoload_spec.rb
2119
2128
  - spec/lutaml/model/namespace_versioning_spec.rb
2120
2129
  - spec/lutaml/model/one_entry_cache_spec.rb
2121
2130
  - spec/lutaml/model/opal_smoke_spec.rb