Skip to content

Commit 7c9f132

Browse files
committed
Recreate EventClassRemapper in contrib/transformations
1 parent a5aeeaa commit 7c9f132

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
module RubyEventStore
4+
module Transformations
5+
class EventClassRemapper
6+
def initialize(class_map)
7+
@class_map = class_map
8+
end
9+
10+
def dump(record)
11+
record
12+
end
13+
14+
def load(record)
15+
Record.new(
16+
event_id: record.event_id,
17+
event_type: class_map[record.event_type] || record.event_type,
18+
data: record.data,
19+
metadata: record.metadata,
20+
timestamp: record.timestamp,
21+
valid_at: record.valid_at
22+
)
23+
end
24+
25+
private
26+
27+
attr_reader :class_map
28+
end
29+
end
30+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require "spec_helper"
2+
3+
module RubyEventStore
4+
module Transformations
5+
::RSpec.describe EventClassRemapper do
6+
let(:time) { Time.now.utc }
7+
let(:uuid) { SecureRandom.uuid }
8+
9+
def record(event_type: "TestEvent")
10+
Record.new(
11+
event_id: uuid,
12+
metadata: {
13+
some: "meta"
14+
},
15+
data: {
16+
some: "value"
17+
},
18+
event_type: event_type,
19+
timestamp: time,
20+
valid_at: time
21+
)
22+
end
23+
24+
let(:changeable_record) { record(event_type: "EventNameBeforeRefactor") }
25+
let(:changed_record) { record(event_type: "SomethingHappened") }
26+
let(:class_map) { { "EventNameBeforeRefactor" => "SomethingHappened" } }
27+
28+
specify "#dump" do
29+
expect(EventClassRemapper.new(class_map).dump(record)).to eq(record)
30+
expect(EventClassRemapper.new(class_map).dump(record)).to eq(record)
31+
end
32+
33+
specify "#load" do
34+
expect(EventClassRemapper.new(class_map).load(record)).to eq(record)
35+
expect(EventClassRemapper.new(class_map).load(changeable_record)).to eq(changed_record)
36+
end
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)