Skip to content

Commit

Permalink
Save events with no event data
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Hallgren committed Apr 12, 2017
1 parent 863697e commit f4f2549
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/http_event_store/event.rb
Expand Up @@ -7,7 +7,7 @@ def initialize(type, data, source_event_uri=nil, event_id=nil, id=nil, position=
end

def validate
[self.event_id, self.type, self.data].any? { |var| var.nil? || var.empty? }
[self.event_id, self.type].any? { |var| var.nil? || var.empty? }
end

def to_json(options)
Expand Down
8 changes: 6 additions & 2 deletions spec/event_store_connection_spec.rb
Expand Up @@ -38,7 +38,7 @@ module HttpEventStore
expect(client.event_store[stream_name].length).to eq 1
end

specify 'can create two new events in stream from array' do
specify 'can create two new events in stream from array' do
create_events_in_es([{ event_type: 'event_type', data: 'event_data' },{ event_type: 'event_type', data: 'event_data' }])
expect(client.event_store[stream_name].length).to eq 2
end
Expand All @@ -50,6 +50,11 @@ module HttpEventStore
expect(client.event_store[stream_name].length).to eq 1
end

specify 'can create event with no event data' do
create_events_in_es({ event_type: 'event_type', data: {} })
expect(client.event_store[stream_name].length).to eq 1
end

specify 'event creation raise error if expected version is incorrect' do
allow(client).to receive(:append_to_stream).and_raise(ClientError.new(400))
expect { create_event_in_es({ event_type: 'event_type', data: 'event_data' }) }.to raise_error(WrongExpectedEventNumber)
Expand All @@ -61,7 +66,6 @@ module HttpEventStore
end

specify 'event creation raise error if method arguments are incorrect' do
expect { create_event_in_es({ event_type: 'event_type', data: nil }) }.to raise_error(IncorrectStreamData)
expect { create_event_in_es({ event_type: nil, data: 'event_data' }) }.to raise_error(IncorrectStreamData)
expect { @connection.append_to_stream(nil, { event_type: 'event_type', data: 'event_data' }) }.to raise_error(IncorrectStreamData)
end
Expand Down

0 comments on commit f4f2549

Please sign in to comment.