Skip to content

Commit

Permalink
to_h is no longer callled on event data
Browse files Browse the repository at this point in the history
This allows putting anything as data, eg. nil, Array, Struct, etc.

However, we added {} as a default value for the data to prevent breaking
applications relying on data being hash and using methods like [] or
fetch.

[#395]
  • Loading branch information
fidel committed Oct 26, 2018
1 parent 867cc89 commit a5de126
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ruby_event_store/lib/ruby_event_store/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Event
# part of your domain such as remote_ip, request_id, correlation_id,
# causation_id etc.
# @return [Event]
def initialize(event_id: SecureRandom.uuid, metadata: nil, data: nil)
def initialize(event_id: SecureRandom.uuid, metadata: nil, data: {})
@event_id = event_id.to_s
@metadata = Metadata.new(metadata.to_h)
@data = data.to_h
@data = data
end

attr_reader :event_id, :metadata, :data
Expand Down
5 changes: 5 additions & 0 deletions ruby_event_store/spec/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ module RubyEventStore
expect(event.metadata.to_h).to eq({})
end

specify 'data can be anything' do
event = Test::TestCreated.new(data: nil)
expect(event.data).to be_nil
end

specify 'UUID should be String' do
event_1 = Test::TestCreated.new({event_id: 1})
event_2 = Test::TestCreated.new
Expand Down

0 comments on commit a5de126

Please sign in to comment.