Skip to content

Commit

Permalink
Merge pull request #413 from RailsEventStore/rl/self-over-ok
Browse files Browse the repository at this point in the history
Make RubyEventStore methods return self instead of ok
mostlyobvious authored Aug 1, 2018
2 parents ea9afb0 + 6684162 commit 701f6f5
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 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
@@ -72,11 +72,11 @@ def append_to_stream(events, stream_name: GLOBAL_STREAM, expected_version: :any)
# Persists new event(s) without notifying any subscribed handlers
#
# @param (see #publish)
# @return [:ok]
# @return [self]
def append(events, stream_name: GLOBAL_STREAM, expected_version: :any)
serialized_events = serialize_events(enrich_events_metadata(events))
append_to_stream_serialized_events(serialized_events, stream_name: stream_name, expected_version: expected_version)
:ok
self
end

# Links already persisted event(s) to a different stream.
@@ -106,10 +106,10 @@ def link_to_stream(event_ids, stream_name:, expected_version: :any)
# longer linked to the stream.
#
# @param stream_name [String] name of the stream to be cleared.
# @return [:ok]
# @return [self]
def delete_stream(stream_name)
repository.delete_stream(Stream.new(stream_name))
:ok
self
end

# @deprecated Use {#read} instead. {https://github.com/RailsEventStore/rails_event_store/releases/tag/v0.30.0 More info}
26 changes: 13 additions & 13 deletions ruby_event_store/spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -7,47 +7,47 @@ module RubyEventStore
let(:client) { RubyEventStore::Client.new(repository: InMemoryRepository.new) }
let(:stream) { SecureRandom.uuid }

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

specify 'append returns :ok when success' do
expect(client.append(TestEvent.new, stream_name: stream)).to eq(:ok)
specify 'append returns client when success' do
expect(client.append(TestEvent.new, stream_name: stream)).to eq(client)
end

specify 'append to default stream when not specified' do
expect(client.append(test_event = TestEvent.new)).to eq(:ok)
expect(client.append(test_event = TestEvent.new)).to eq(client)
expect(client.read.limit(100).each.to_a).to eq([test_event])
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 'delete_stream returns :ok when success' do
expect(client.delete_stream(stream)).to eq(:ok)
specify 'delete_stream returns client when success' do
expect(client.delete_stream(stream)).to eq(client)
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 701f6f5

Please sign in to comment.