Skip to content

Commit 41b08c4

Browse files
committed
ZOMG
* we actually should check both variants, with SymbolizeMetadataKeys as in the mappers we provide and when transformation is used standalone — in case someone composes mappers as they wish At this point I don't understand why ostruct would always have symbols, while active_support_time_with_zone would differentiate. WELP.
1 parent e3c7ad8 commit 41b08c4

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

ruby_event_store/lib/ruby_event_store/mappers/transformation/preserve_types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def restore_type(argument, type)
143143
case type
144144
when Hash
145145
argument.reduce({}) do |hash, (key, value)|
146-
key_type, value_type = type.fetch(key.to_sym)
146+
key_type, value_type = type.fetch(key.to_sym) { type.fetch(key.to_s) }
147147
hash.merge(restore_type(key, key_type) => restore_type(value, value_type))
148148
end
149149
when Array

ruby_event_store/spec/mappers/transformation/preserve_types_spec.rb

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ module Transformation
113113
)
114114
end
115115

116+
let(:transformation_with_symbolized_metadata) do
117+
Pipeline.new(transformation, SymbolizeMetadataKeys.new, to_domain_event: NULL)
118+
end
119+
116120
specify "#dump" do
117121
result = transformation.dump(record)
118122
expect(result).to eq(dump_of_record)
@@ -338,16 +342,23 @@ module Transformation
338342
event_id: uuid,
339343
metadata: {
340344
},
341-
data: active_support_time_with_zone,
345+
data: {
346+
active_support_time_with_zone: active_support_time_with_zone,
347+
},
342348
event_type: "TestEvent",
343349
timestamp: nil,
344350
valid_at: nil,
345351
)
346352

347353
expect(transformation.dump(record).metadata[:types]).to eq(
348-
{ data: "ActiveSupport::TimeWithZone", metadata: {} },
354+
{ data: { "active_support_time_with_zone" => %w[Symbol ActiveSupport::TimeWithZone] }, metadata: {} },
349355
)
350-
expect(transformation.load(transformation.dump(record))).to eq(record)
356+
expect(transformation_with_symbolized_metadata.dump(record).metadata[:types]).to eq(
357+
{ data: { active_support_time_with_zone: %w[Symbol ActiveSupport::TimeWithZone] }, metadata: {} },
358+
)
359+
[transformation, transformation_with_symbolized_metadata].each do |t|
360+
expect(t.load(t.dump(record))).to eq(record)
361+
end
351362
ensure
352363
Time.zone = current_tz
353364
end
@@ -365,14 +376,23 @@ module Transformation
365376
event_id: uuid,
366377
metadata: {
367378
},
368-
data: ostruct,
379+
data: {
380+
ostruct: ostruct,
381+
},
369382
event_type: "TestEvent",
370383
timestamp: nil,
371384
valid_at: nil,
372385
)
373386

374-
expect(transformation.dump(record).metadata[:types]).to eq({ data: "OpenStruct", metadata: {} })
375-
expect(transformation.load(transformation.dump(record))).to eq(record)
387+
expect(transformation.dump(record).metadata[:types]).to eq(
388+
{ data: { ostruct: %w[Symbol OpenStruct] }, metadata: {} },
389+
)
390+
expect(transformation_with_symbolized_metadata.dump(record).metadata[:types]).to eq(
391+
{ data: { ostruct: %w[Symbol OpenStruct] }, metadata: {} },
392+
)
393+
[transformation, transformation_with_symbolized_metadata].each do |t|
394+
expect(t.load(t.dump(record))).to eq(record)
395+
end
376396
end
377397

378398
specify "handle classes with overloaded name like ActiveSupport::TimeWithZone < 7.1" do

0 commit comments

Comments
 (0)