Skip to content

Commit d3463ed

Browse files
lukaszreszkefidel
authored andcommitted
Using projection with event type defined by event's class
During an attempt to introduce event_type_resolver into projection I wrote following test. The idea is that you can use two different versions of event with class level method defining the event type. In that case, and in usage presented as in test, the event_type_resolver doesn't bring any value to the projection class. So for now I removed it. Perhaps it does make more sense if we're thinking of other way of using projections?
1 parent 2143be2 commit d3463ed

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: ruby_event_store/spec/projection_spec.rb

+28
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,33 @@ module RubyEventStore
228228

229229
expect(state).to eq(initial_state)
230230
end
231+
232+
specify "events with event type defined as class method" do
233+
class Snowflake < Event
234+
def self.event_type
235+
"snowflake"
236+
end
237+
end
238+
239+
class SnowflakeV2 < Event
240+
def self.event_type
241+
"snowflake"
242+
end
243+
end
244+
245+
event_store.append(Snowflake.new(data: { arms: 13 }), stream_name: "snowflake$1")
246+
event_store.append(SnowflakeV2.new(data: { arms: 11 }), stream_name: "snowflake$1")
247+
248+
state =
249+
Projection
250+
.init({ snowflake: 0 })
251+
.on(Snowflake, SnowflakeV2) do |state, event|
252+
state[event.class.event_type.to_sym] += event.data.fetch(:arms)
253+
state
254+
end
255+
.call(event_store.read.stream("snowflake$1"))
256+
257+
expect(state).to eq({ snowflake: 24 })
258+
end
231259
end
232260
end

0 commit comments

Comments
 (0)