diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index 0ed4217195..419342912d 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -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. diff --git a/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb b/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb index bc3ad5dd62..fad6f0a89f 100644 --- a/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb +++ b/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb @@ -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 diff --git a/ruby_event_store/spec/client_spec.rb b/ruby_event_store/spec/client_spec.rb index d9a4a88b8b..637cbb2d61 100644 --- a/ruby_event_store/spec/client_spec.rb +++ b/ruby_event_store/spec/client_spec.rb @@ -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