Skip to content

Commit

Permalink
Make RubyEventStore#publish return self instead of :ok
Browse files Browse the repository at this point in the history
Issue: #392
  • Loading branch information
swistak35 committed Aug 1, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 75f71be commit 9ede61d
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ruby_event_store/lib/ruby_event_store/client.rb
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ def initialize(repository:,
# @param events [Array<Event, Proto>, Event, Proto] event(s)
# @param stream_name [String] name of the stream for persisting events.
# @param expected_version [:any, :auto, :none, Integer] controls optimistic locking strategy. {http://railseventstore.org/docs/expected_version/ Read more}
# @return [:ok]
# @return [self]
def publish(events, stream_name: GLOBAL_STREAM, expected_version: :any)
enriched_events = enrich_events_metadata(events)
serialized_events = serialize_events(enriched_events)
@@ -36,7 +36,7 @@ def publish(events, stream_name: GLOBAL_STREAM, expected_version: :any)
broker.(event, serialized_event)
end
end
:ok
self
end

# @deprecated Use {#publish} instead
14 changes: 7 additions & 7 deletions ruby_event_store/spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ module RubyEventStore
let(:stream) { SecureRandom.uuid }

specify 'publish returns :ok when success' do
expect(client.publish(TestEvent.new)).to eq(:ok)
expect(client.publish(TestEvent.new)).to eq(client)
end

specify 'append returns client when success' do
@@ -21,7 +21,7 @@ module RubyEventStore
end

specify 'publish to default stream when not specified' do
expect(client.publish([test_event = TestEvent.new])).to eq(:ok)
expect(client.publish([test_event = TestEvent.new])).to eq(client)
expect(client.read.limit(100).each.to_a).to eq([test_event])
end

@@ -30,24 +30,24 @@ module RubyEventStore
end

specify 'publish to default stream when not specified' do
expect(client.publish(test_event = TestEvent.new)).to eq(:ok)
expect(client.publish(test_event = TestEvent.new)).to eq(client)
expect(client.read.limit(100).each.to_a).to eq([test_event])
end

specify 'publish first event, expect any stream state' do
expect(client.publish(first_event = TestEvent.new, stream_name: stream)).to eq(:ok)
expect(client.publish(first_event = TestEvent.new, stream_name: stream)).to eq(client)
expect(client.read.stream(stream).each.to_a).to eq([first_event])
end

specify 'publish next event, expect any stream state' do
client.append(first_event = TestEvent.new, stream_name: stream)

expect(client.publish(second_event = TestEvent.new, stream_name: stream)).to eq(:ok)
expect(client.publish(second_event = TestEvent.new, stream_name: stream)).to eq(client)
expect(client.read.stream(stream).each.to_a).to eq([first_event, second_event])
end

specify 'publish first event, expect empty stream' do
expect(client.publish(first_event = TestEvent.new, stream_name: stream, expected_version: :none)).to eq(:ok)
expect(client.publish(first_event = TestEvent.new, stream_name: stream, expected_version: :none)).to eq(client)
expect(client.read.stream(stream).each.to_a).to eq([first_event])
end

@@ -61,7 +61,7 @@ module RubyEventStore
specify 'publish event, expect last event to be the last read one' do
client.append(first_event = TestEvent.new, stream_name: stream)

expect(client.publish(second_event = TestEvent.new, stream_name: stream, expected_version: 0)).to eq(:ok)
expect(client.publish(second_event = TestEvent.new, stream_name: stream, expected_version: 0)).to eq(client)
expect(client.read.stream(stream).each.to_a).to eq([first_event, second_event])
end

0 comments on commit 9ede61d

Please sign in to comment.