deimos-ruby 1.13.2 → 1.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +6 -0
- data/deimos-ruby.gemspec +1 -0
- data/lib/deimos/active_record_consume/message_consumption.rb +2 -1
- data/lib/deimos/config/configuration.rb +4 -0
- data/lib/deimos/schema_backends/avro_base.rb +1 -1
- data/lib/deimos/schema_class/base.rb +17 -0
- data/lib/deimos/test_helpers.rb +1 -1
- data/lib/deimos/version.rb +1 -1
- data/lib/generators/deimos/active_record/templates/migration.rb.tt +5 -3
- data/lib/generators/deimos/active_record_generator.rb +1 -1
- data/lib/generators/deimos/schema_class/templates/schema_class.rb.tt +0 -7
- data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +10 -1
- data/lib/generators/deimos/schema_class_generator.rb +19 -7
- data/spec/active_record_consumer_spec.rb +21 -0
- data/spec/generators/active_record_generator_spec.rb +4 -2
- data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +37 -24
- data/spec/generators/schema_class_generator_spec.rb +93 -55
- data/spec/producer_spec.rb +1 -1
- data/spec/schemas/com/my-namespace/MySchemaId_key.avsc +12 -0
- data/spec/schemas/generated.rb +159 -0
- data/spec/schemas/my_nested_schema.rb +117 -0
- data/spec/{schema_classes → schemas}/my_schema.rb +1 -0
- data/spec/{schema_classes → schemas}/my_schema_key.rb +1 -0
- data/spec/schemas/my_schema_with_circular_reference.rb +77 -0
- data/spec/schemas/my_schema_with_complex_type.rb +239 -0
- data/spec/{schema_classes/generated.rb → snapshots/consumers-no-nest.snap} +20 -1
- data/spec/snapshots/consumers.snap +161 -0
- data/spec/snapshots/consumers_and_producers-no-nest.snap +397 -0
- data/spec/snapshots/consumers_and_producers.snap +377 -0
- data/spec/{schema_classes/my_schema_with_circular_reference.rb → snapshots/consumers_circular-no-nest.snap} +37 -26
- data/spec/snapshots/consumers_circular.snap +79 -0
- data/spec/{schema_classes/my_schema_with_complex_types.rb → snapshots/consumers_complex_types-no-nest.snap} +57 -22
- data/spec/snapshots/consumers_complex_types.snap +241 -0
- data/spec/{schema_classes/my_nested_schema.rb → snapshots/consumers_nested-no-nest.snap} +12 -1
- data/spec/snapshots/consumers_nested.snap +119 -0
- data/spec/snapshots/producers_with_key-no-nest.snap +95 -0
- data/spec/snapshots/producers_with_key.snap +95 -0
- data/spec/spec_helper.rb +4 -1
- metadata +54 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d94fcbeb955de22fde06b29f63809cae7305d91f029ba8ec0b36e4dbbe037a2
|
4
|
+
data.tar.gz: 611e5cc68a5d9e661ff692f05692d7ba24e4804f5761479802a632cbdd2a0fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5100b19ede901f0b7a4e20f0aa6c15d487e9355d95ea46d984c8fcb587039be4be9529991197148e630ad3670c65d79ab0653ff57c28e224236a4d966bebe7e1
|
7
|
+
data.tar.gz: '082ad2e7be4d85fa3e8e242cdc7f192a35f99424675f5bddc3e11a3c19477ce5abf0df629117ca4f714ca107ea5be0a93a8aa5041a1f67cc628517f451005bb1'
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
# 1.14.1 - 2022-05-25
|
11
|
+
|
12
|
+
- Fix: When using key schemas, ActiveRecordConsumers were not finding the record by default.
|
13
|
+
|
14
|
+
# 1.14.0 - 2022-05-16
|
15
|
+
|
16
|
+
- **Breaking Change**: Nest sub-schemas by default into their parent schemas when generating classes.
|
17
|
+
- Add the `nest_child_schemas` option to essentially bring back the previous behavior in terms of code use (the actual classes will be separated out into different files).
|
18
|
+
|
19
|
+
# 1.13.3 - 2022-05-10
|
20
|
+
|
21
|
+
- Some cleanup on the active_record generator
|
22
|
+
- Fix crash with `test_consume_message` when using schema classes
|
23
|
+
- Add `[]=` and `merge` methods on the base schema class
|
24
|
+
|
10
25
|
# 1.13.2 - 2022-04-07
|
11
26
|
|
12
27
|
- Fix an issue with generating schema classes for schemas containing an enum with default value
|
data/README.md
CHANGED
@@ -818,6 +818,12 @@ Add the following configurations to start using generated schema classes in your
|
|
818
818
|
Additionally, you can enable or disable the usage of schema classes for a particular consumer or producer with the
|
819
819
|
`use_schema_classes` config. See [Configuration](./docs/CONFIGURATION.md#defining-producers).
|
820
820
|
|
821
|
+
Note that if you have a schema in your repo but have not configured a producer or consumer, the generator will **not** generate a schema class for it. This is because you need to supply the `key_config` for the generator to know how to handle the schema key.
|
822
|
+
|
823
|
+
One additional configuration option indicates whether nested records should be generated as top-level classes or would remain nested inside the generated class for its parent schema. The default is to nest them, as a flattened structure can have one sub-schema clobber another sub-schema defined in a different top-level schema.
|
824
|
+
|
825
|
+
config.schema.nest_child_schemas = false # Flatten all classes into one directory
|
826
|
+
|
821
827
|
### Consumer
|
822
828
|
|
823
829
|
The consumer interface uses the `decode_message` method to turn JSON hash into the Schemas
|
data/deimos-ruby.gemspec
CHANGED
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency('rspec', '~> 3')
|
40
40
|
spec.add_development_dependency('rspec_junit_formatter', '~>0.3')
|
41
41
|
spec.add_development_dependency('rspec-rails', '~> 4')
|
42
|
+
spec.add_development_dependency('rspec-snapshot', '~> 2.0')
|
42
43
|
spec.add_development_dependency('rubocop', '0.89.0')
|
43
44
|
spec.add_development_dependency('rubocop-rspec', '1.42.0')
|
44
45
|
spec.add_development_dependency('sqlite3', '~> 1.3')
|
@@ -13,7 +13,8 @@ module Deimos
|
|
13
13
|
# @param key [Object]
|
14
14
|
# @return [ActiveRecord::Base]
|
15
15
|
def fetch_record(klass, _payload, key)
|
16
|
-
|
16
|
+
fetch_key = key.is_a?(Hash) && key.size == 1 ? key.values.first : key
|
17
|
+
klass.unscoped.where(klass.primary_key => fetch_key).first
|
17
18
|
end
|
18
19
|
|
19
20
|
# Assign a key to a new record.
|
@@ -343,6 +343,10 @@ module Deimos
|
|
343
343
|
# Set to true to use the generated schema classes in your application
|
344
344
|
# @return [Boolean]
|
345
345
|
setting :use_schema_classes, false
|
346
|
+
|
347
|
+
# Set to false to generate child schemas as their own files.
|
348
|
+
# @return [Boolean]
|
349
|
+
setting :nest_child_schemas, true
|
346
350
|
end
|
347
351
|
|
348
352
|
# The configured metrics provider.
|
@@ -96,7 +96,7 @@ module Deimos
|
|
96
96
|
# @param schema [Avro::Schema::NamedSchema] A named schema
|
97
97
|
# @return [String]
|
98
98
|
def self.schema_classname(schema)
|
99
|
-
schema.name.underscore.camelize
|
99
|
+
schema.name.underscore.camelize.singularize
|
100
100
|
end
|
101
101
|
|
102
102
|
# Converts Avro::Schema::NamedSchema's to String form for generated YARD docs.
|
@@ -29,6 +29,23 @@ module Deimos
|
|
29
29
|
raise NotImplementedError
|
30
30
|
end
|
31
31
|
|
32
|
+
# @param key [String|Symbol]
|
33
|
+
# @param val [Object]
|
34
|
+
def []=(key, val)
|
35
|
+
self.send("#{key}=", val)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Merge a hash or an identical schema object with this one and return a new object.
|
39
|
+
# @param other_hash [Hash|SchemaClasses::Base]
|
40
|
+
# @return [SchemaClasses::Base]
|
41
|
+
def merge(other_hash)
|
42
|
+
obj = self.class.new(**self.to_h.symbolize_keys)
|
43
|
+
other_hash.to_h.each do |k, v|
|
44
|
+
obj.send("#{k}=", v)
|
45
|
+
end
|
46
|
+
obj
|
47
|
+
end
|
48
|
+
|
32
49
|
# :nodoc:
|
33
50
|
def ==(other)
|
34
51
|
comparison = other
|
data/lib/deimos/test_helpers.rb
CHANGED
@@ -188,7 +188,7 @@ module Deimos
|
|
188
188
|
&block)
|
189
189
|
raise 'Cannot have both call_original and be given a block!' if call_original && block_given?
|
190
190
|
|
191
|
-
payload
|
191
|
+
payload.stringify_keys! if payload.respond_to?(:stringify_keys!)
|
192
192
|
handler_class = if handler_class_or_topic.is_a?(String)
|
193
193
|
_get_handler_class_from_topic(handler_class_or_topic)
|
194
194
|
else
|
data/lib/deimos/version.rb
CHANGED
@@ -6,7 +6,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
|
|
6
6
|
end
|
7
7
|
create_table :<%= table_name %> do |t|
|
8
8
|
<%- fields.each do |key| -%>
|
9
|
-
<%- next if %w(id message_id timestamp).include?(key.name) -%>
|
9
|
+
<%- next if %w(id message_id timestamp updated_at created_at).include?(key.name) -%>
|
10
10
|
<%- sql_type = schema_base.sql_type(key)
|
11
11
|
if %w(record array map).include?(sql_type)
|
12
12
|
conn = ActiveRecord::Base.connection
|
@@ -15,9 +15,11 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
|
|
15
15
|
-%>
|
16
16
|
t.<%= sql_type %> :<%= key.name %>
|
17
17
|
<%- end -%>
|
18
|
-
end
|
19
18
|
|
20
|
-
|
19
|
+
t.timestamps
|
20
|
+
|
21
|
+
# TODO add indexes as necessary
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
def down
|
@@ -72,7 +72,7 @@ module Deimos
|
|
72
72
|
# :nodoc:
|
73
73
|
def generate
|
74
74
|
migration_template('migration.rb', "db/migrate/create_#{table_name.underscore}.rb")
|
75
|
-
template('model.rb', "app/models/#{table_name.underscore}.rb")
|
75
|
+
template('model.rb', "app/models/#{table_name.underscore.singularize}.rb")
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -2,13 +2,6 @@
|
|
2
2
|
|
3
3
|
# This file is autogenerated by Deimos, Do NOT modify
|
4
4
|
module Schemas
|
5
|
-
<% if @sub_schema_templates.present? && @sub_schema_templates.any? -%>
|
6
|
-
### Secondary Schema Classes ###
|
7
|
-
<% end -%>
|
8
|
-
<%- @sub_schema_templates.each do |schema_template| -%>
|
9
|
-
<%=- schema_template %>
|
10
|
-
|
11
|
-
<%- end -%>
|
12
5
|
### Primary Schema Class ###
|
13
6
|
<%=- @main_class_definition -%>
|
14
7
|
|
@@ -1,6 +1,15 @@
|
|
1
1
|
# Autogenerated Schema for Record at <%= @current_schema.namespace %>.<%= @current_schema.name %>
|
2
2
|
class <%= Deimos::SchemaBackends::AvroBase.schema_classname(@current_schema) %> < Deimos::SchemaClass::Record
|
3
|
-
|
3
|
+
<% if @sub_schema_templates.present? -%>
|
4
|
+
|
5
|
+
### Secondary Schema Classes ###
|
6
|
+
<%- @sub_schema_templates.each do |schema_template| -%>
|
7
|
+
<%=- schema_template.gsub(/^/, " ") %>
|
8
|
+
|
9
|
+
<%- end -%>
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
<%- if @field_assignments.select{ |h| h[:is_schema_class] }.any? -%>
|
4
13
|
### Attribute Readers ###
|
5
14
|
<%- @field_assignments.select{ |h| h[:is_schema_class] }.each do |method_definition| -%>
|
6
15
|
# @return [<%= method_definition[:deimos_type] %>]
|
@@ -86,20 +86,32 @@ module Deimos
|
|
86
86
|
# @param key_schema_base[Avro::Schema::NamedSchema]
|
87
87
|
def generate_class_from_schema_base(schema_base, key_schema_base: nil)
|
88
88
|
@discovered_schemas = Set.new
|
89
|
+
@sub_schema_templates = []
|
89
90
|
schemas = collect_all_schemas(schema_base.schema_store.schemas.values)
|
90
91
|
|
92
|
+
main_schema = schemas.find { |s| s.name == schema_base.schema }
|
91
93
|
sub_schemas = schemas.reject { |s| s.name == schema_base.schema }.sort_by(&:name)
|
92
|
-
|
93
|
-
|
94
|
+
if Deimos.config.schema.nest_child_schemas
|
95
|
+
@sub_schema_templates = sub_schemas.map do |schema|
|
96
|
+
_generate_class_template_from_schema(schema)
|
97
|
+
end
|
98
|
+
write_file(main_schema, key_schema_base)
|
99
|
+
else
|
100
|
+
write_file(main_schema, key_schema_base)
|
101
|
+
sub_schemas.each do |schema|
|
102
|
+
write_file(schema, nil)
|
103
|
+
end
|
94
104
|
end
|
105
|
+
end
|
95
106
|
|
96
|
-
|
97
|
-
|
107
|
+
# @param schema [Avro::Schema::NamedSchema]
|
108
|
+
# @param key_schema_base [Avro::Schema::NamedSchema, nil]
|
109
|
+
def write_file(schema, key_schema_base)
|
110
|
+
class_template = _generate_class_template_from_schema(schema, key_schema_base)
|
98
111
|
@main_class_definition = class_template
|
99
112
|
|
100
|
-
file_prefix =
|
101
|
-
|
102
|
-
filename = "#{Deimos.config.schema.generated_class_path}/#{namespace_path}/#{file_prefix}.rb"
|
113
|
+
file_prefix = schema.name.underscore.singularize
|
114
|
+
filename = "#{Deimos.config.schema.generated_class_path}/#{file_prefix}.rb"
|
103
115
|
template(SCHEMA_CLASS_FILE, filename, force: true)
|
104
116
|
end
|
105
117
|
|
@@ -39,6 +39,14 @@ module ActiveRecordConsumerTest
|
|
39
39
|
end
|
40
40
|
stub_const('MyConsumer', consumer_class)
|
41
41
|
|
42
|
+
consumer_class = Class.new(Deimos::ActiveRecordConsumer) do
|
43
|
+
schema 'MySchemaWithDateTimes'
|
44
|
+
namespace 'com.my-namespace'
|
45
|
+
key_config schema: 'MySchemaId_key'
|
46
|
+
record_class Widget
|
47
|
+
end
|
48
|
+
stub_const('MyConsumerWithKey', consumer_class)
|
49
|
+
|
42
50
|
consumer_class = Class.new(Deimos::ActiveRecordConsumer) do
|
43
51
|
schema 'MySchema'
|
44
52
|
namespace 'com.my-namespace'
|
@@ -126,6 +134,19 @@ module ActiveRecordConsumerTest
|
|
126
134
|
travel_back
|
127
135
|
end
|
128
136
|
|
137
|
+
it 'should find widgets with a schema key' do
|
138
|
+
widget1 = Widget.create!(test_id: 'id1')
|
139
|
+
expect(widget1.some_int).to be_nil
|
140
|
+
test_consume_message(MyConsumerWithKey, {
|
141
|
+
test_id: 'id1',
|
142
|
+
some_int: 3
|
143
|
+
},
|
144
|
+
key: { id: widget1.id },
|
145
|
+
call_original: true)
|
146
|
+
expect(widget1.reload.some_int).to eq(3)
|
147
|
+
expect(Widget.count).to eq(1)
|
148
|
+
end
|
149
|
+
|
129
150
|
it 'should find widgets by custom logic' do
|
130
151
|
widget1 = Widget.create!(test_id: 'id1')
|
131
152
|
expect(widget1.some_int).to be_nil
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# For testing the generated class.
|
4
|
-
RSpec.describe Schemas::
|
4
|
+
RSpec.describe Schemas::MySchemaWithComplexType do
|
5
5
|
let(:payload_hash) do
|
6
6
|
{
|
7
7
|
test_id: 'test id',
|
@@ -9,16 +9,16 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
9
9
|
test_string_array: %w(abc def),
|
10
10
|
test_int_array: [123, 456],
|
11
11
|
some_integer_map: { 'int_1' => 1, 'int_2' => 2 },
|
12
|
-
some_record: Schemas::ARecord.new(a_record_field: 'field 1'),
|
13
|
-
some_optional_record: Schemas::ARecord.new(a_record_field: 'field 2'),
|
14
|
-
some_record_array: [Schemas::ARecord.new(a_record_field: 'field 3'),
|
15
|
-
Schemas::ARecord.new(a_record_field: 'field 4')],
|
12
|
+
some_record: Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 1'),
|
13
|
+
some_optional_record: Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 2'),
|
14
|
+
some_record_array: [Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 3'),
|
15
|
+
Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 4')],
|
16
16
|
some_record_map: {
|
17
|
-
'record_1' => Schemas::ARecord.new(a_record_field: 'field 5'),
|
18
|
-
'record_2' => Schemas::ARecord.new(a_record_field: 'field 6')
|
17
|
+
'record_1' => Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 5'),
|
18
|
+
'record_2' => Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 6')
|
19
19
|
},
|
20
|
-
some_enum_array: [Schemas::AnEnum.new('sym1'),
|
21
|
-
Schemas::AnEnum.new('sym2')]
|
20
|
+
some_enum_array: [Schemas::MySchemaWithComplexType::AnEnum.new('sym1'),
|
21
|
+
Schemas::MySchemaWithComplexType::AnEnum.new('sym2')]
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
@@ -57,7 +57,9 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
let(:schema_fields) do
|
60
|
-
%w(test_id test_float test_int_array test_optional_int test_string_array some_integer_map
|
60
|
+
%w(test_id test_float test_int_array test_optional_int test_string_array some_integer_map
|
61
|
+
some_record some_optional_record some_record_array some_record_map some_enum_array
|
62
|
+
some_optional_enum some_enum_with_default)
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'should return the name of the schema and namespace' do
|
@@ -113,7 +115,8 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
113
115
|
it 'should set some_record if it is not provided' do
|
114
116
|
payload_hash.delete(:some_record)
|
115
117
|
klass = described_class.new(**payload_hash)
|
116
|
-
expect(klass.some_record).
|
118
|
+
expect(klass.some_record).
|
119
|
+
to eq(Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'Test String'))
|
117
120
|
end
|
118
121
|
|
119
122
|
it 'should set some_record to nil' do
|
@@ -136,25 +139,26 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
136
139
|
|
137
140
|
it 'should get the value of some_record_array' do
|
138
141
|
some_record_array = klass.some_record_array
|
139
|
-
expect(some_record_array.first).to be_instance_of(Schemas::ARecord)
|
142
|
+
expect(some_record_array.first).to be_instance_of(Schemas::MySchemaWithComplexType::ARecord)
|
140
143
|
expect(some_record_array.first.a_record_field).to eq('field 3')
|
141
144
|
end
|
142
145
|
|
143
146
|
it 'should get the value of some_record_map' do
|
144
147
|
some_record_map = klass.some_record_map
|
145
|
-
expect(some_record_map['record_1']).
|
148
|
+
expect(some_record_map['record_1']).
|
149
|
+
to be_instance_of(Schemas::MySchemaWithComplexType::ARecord)
|
146
150
|
expect(some_record_map['record_1'].a_record_field).to eq('field 5')
|
147
151
|
end
|
148
152
|
|
149
153
|
it 'should get the value of some_enum_array' do
|
150
154
|
some_enum_array = klass.some_enum_array
|
151
|
-
expect(some_enum_array.first).to be_instance_of(Schemas::AnEnum)
|
155
|
+
expect(some_enum_array.first).to be_instance_of(Schemas::MySchemaWithComplexType::AnEnum)
|
152
156
|
expect(some_enum_array.first.an_enum).to eq('sym1')
|
153
157
|
end
|
154
158
|
|
155
159
|
it 'should get the value of some_record' do
|
156
160
|
record = klass.some_record
|
157
|
-
expect(record).to be_instance_of(Schemas::ARecord)
|
161
|
+
expect(record).to be_instance_of(Schemas::MySchemaWithComplexType::ARecord)
|
158
162
|
expect(record.a_record_field).to eq('field 1')
|
159
163
|
expect(record.to_h).to eq({ 'a_record_field' => 'field 1' })
|
160
164
|
end
|
@@ -175,33 +179,42 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
175
179
|
end
|
176
180
|
|
177
181
|
it 'should modify the value of some_optional_record' do
|
178
|
-
expect(klass.some_optional_record).
|
179
|
-
|
182
|
+
expect(klass.some_optional_record).
|
183
|
+
to eq(Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 2'))
|
184
|
+
klass.some_optional_record = Schemas::MySchemaWithComplexType::ARecord.
|
185
|
+
new(a_record_field: 'new field')
|
180
186
|
|
181
|
-
expect(klass.some_optional_record).to eq(Schemas::ARecord.
|
187
|
+
expect(klass.some_optional_record).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
188
|
+
new(a_record_field: 'new field'))
|
182
189
|
expect(klass.some_optional_record.as_json).to eq({ 'a_record_field' => 'new field' })
|
183
190
|
end
|
184
191
|
|
185
192
|
it 'should accept a hash object inner records' do
|
186
193
|
klass.some_optional_record = { a_record_field: 'new field' }
|
187
|
-
expect(klass.some_optional_record).to eq(Schemas::ARecord.
|
194
|
+
expect(klass.some_optional_record).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
195
|
+
new(a_record_field: 'new field'))
|
188
196
|
expect(klass.some_optional_record.as_json).to eq({ 'a_record_field' => 'new field' })
|
189
197
|
end
|
190
198
|
|
191
199
|
it 'should modify the value of some_enum_array' do
|
192
200
|
klass.some_enum_array.first.an_enum = 'new_sym'
|
193
|
-
expect(klass.some_enum_array.first).
|
201
|
+
expect(klass.some_enum_array.first).
|
202
|
+
to eq(Schemas::MySchemaWithComplexType::AnEnum.new('new_sym'))
|
194
203
|
|
195
|
-
klass.some_enum_array.second.an_enum = Schemas::AnEnum.
|
204
|
+
klass.some_enum_array.second.an_enum = Schemas::MySchemaWithComplexType::AnEnum.
|
205
|
+
new('other_sym')
|
196
206
|
expect(klass.some_enum_array.second.an_enum).to eq('other_sym')
|
197
207
|
end
|
198
208
|
|
199
209
|
it 'should modify the value of some_record_map' do
|
200
210
|
klass.some_record_map['record_1'].a_record_field = 'new field'
|
201
|
-
expect(klass.some_record_map['record_1']).to eq(Schemas::ARecord.
|
211
|
+
expect(klass.some_record_map['record_1']).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
212
|
+
new(a_record_field: 'new field'))
|
202
213
|
|
203
|
-
klass.some_record_map['record_2'] = Schemas::ARecord.
|
204
|
-
|
214
|
+
klass.some_record_map['record_2'] = Schemas::MySchemaWithComplexType::ARecord.
|
215
|
+
new(a_record_field: 'other field')
|
216
|
+
expect(klass.some_record_map['record_2']).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
217
|
+
new(a_record_field: 'other field'))
|
205
218
|
end
|
206
219
|
end
|
207
220
|
end
|