Skip to content

Commit

Permalink
Add search_streams in RubyEventStore::Client
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszreszke committed Mar 19, 2024
1 parent 053dcd8 commit 8a1d9f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ruby_event_store/lib/ruby_event_store/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def streams_of(event_id)
repository.streams_of(event_id)
end

def search_streams(stream)
repository.search_streams(stream)
end

# Gets position of the event in given stream
#
# The position is always nonnegative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def search_streams(stream_name)
.select { |name,| name.downcase.include?(stream_name.downcase) }
.to_a
.reverse
.to_h
.map { |name,| Stream.new(name) }
end

Expand Down
21 changes: 21 additions & 0 deletions ruby_event_store/spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,27 @@ module RubyEventStore
end
end

specify "finds streams that are similar to searching criteria" do
event_1 = OrderCreated.new(event_id: SecureRandom.uuid, data: {})
event_2 = OrderCreated.new(event_id: SecureRandom.uuid, data: {})
event_3 = OrderCreated.new(event_id: SecureRandom.uuid, data: {})
stream_1 = Stream.new("stream-1")
stream_2 = Stream.new("stream-2")
stream_3 = Stream.new("stream-3")

client.append(event_1, stream_name: stream_1.name)
client.append(event_2, stream_name: stream_2.name)
client.append(event_3, stream_name: stream_3.name)

expect(client.search_streams("str")).to eq [stream_3, stream_2, stream_1]
expect(client.search_streams("Str")).to eq [stream_3, stream_2, stream_1]
expect(client.search_streams("sTr")).to eq [stream_3, stream_2, stream_1]
expect(client.search_streams("stream-1")).to eq [stream_1]
expect(client.search_streams("stream-2")).to eq [stream_2]
expect(client.search_streams("stream-3")).to eq [stream_3]
expect(client.search_streams("stream-4")).to eq []
end

describe "#subscribers_for" do
specify do
handler = Subscribers::ValidHandler.new
Expand Down

0 comments on commit 8a1d9f9

Please sign in to comment.