Skip to content

Commit 067e9b7

Browse files
pjurewiczfidel
authored andcommitted
Validate starting and ending specification events only on execution
No longer check if a starting or ending event exists while building a scope. It will fail on execution anyway.
1 parent 9c85f0c commit 067e9b7

File tree

4 files changed

+4
-31
lines changed

4 files changed

+4
-31
lines changed

ruby_event_store/lib/ruby_event_store/specification.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def stream(stream_name)
2828
# @return [Specification]
2929
def from(start)
3030
raise InvalidPageStart if start.nil? || start.empty?
31-
raise EventNotFound.new(start) unless reader.has_event?(start)
3231
Specification.new(reader, result.dup { |r| r.start = start })
3332
end
3433

@@ -39,7 +38,6 @@ def from(start)
3938
# @return [Specification]
4039
def to(stop)
4140
raise InvalidPageStop if stop.nil? || stop.empty?
42-
raise EventNotFound.new(stop) unless reader.has_event?(stop)
4341
Specification.new(reader, result.dup { |r| r.stop = stop })
4442
end
4543

ruby_event_store/lib/ruby_event_store/specification_reader.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ def count(specification_result)
2929
repository.count(specification_result)
3030
end
3131

32-
# @api private
33-
# @private
34-
def has_event?(event_id)
35-
repository.has_event?(event_id)
36-
end
37-
3832
private
3933

4034
attr_reader :repository, :mapper

ruby_event_store/spec/client_spec.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,6 @@ module RubyEventStore
341341
expect { client.read.backward.stream("").limit(100).to_a }.to raise_error(IncorrectStreamData)
342342
end
343343

344-
specify "raise exception if event_id does not exist" do
345-
expect { client.read.stream("stream_name").from("0").limit(100).to_a }.to raise_error(
346-
EventNotFound,
347-
/Event not found: 0/
348-
)
349-
expect { client.read.backward.stream("stream_name").from("0").limit(100).to_a }.to raise_error(EventNotFound, /0/)
350-
end
351-
352-
specify "raise exception if event_id is not given or invalid" do
353-
expect { client.read.stream("stream_name").from(nil).limit(100).to_a }.to raise_error(InvalidPageStart)
354-
expect { client.read.backward.stream("stream_name").from(:invalid).limit(100).to_a }.to raise_error(EventNotFound)
355-
end
356-
357344
specify "fails when page size is invalid" do
358345
expect { client.read.stream("stream_name").limit(0).to_a }.to raise_error(InvalidPageSize)
359346
expect { client.read.backward.stream("stream_name").limit(0).to_a }.to raise_error(InvalidPageSize)
@@ -410,9 +397,11 @@ module RubyEventStore
410397
client.publish(event, stream_name: "stream_name")
411398
end
412399

413-
expect { client.read.stream("stream_name").from(SecureRandom.uuid).limit(100).to_a }.to raise_error(EventNotFound)
400+
expect { client.read.stream("stream_name").from(SecureRandom.uuid).limit(100).to_a }.to raise_error(
401+
EventNotFoundInStream
402+
)
414403
expect { client.read.backward.stream("stream_name").from(SecureRandom.uuid).limit(100).to_a }.to raise_error(
415-
EventNotFound
404+
EventNotFoundInStream
416405
)
417406
end
418407

ruby_event_store/spec/specification_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,13 @@ module RubyEventStore
3838

3939
specify { expect { specification.from(nil) }.to raise_error(InvalidPageStart) }
4040
specify { expect { specification.from("") }.to raise_error(InvalidPageStart) }
41-
specify { expect { specification.from(:dummy) }.to raise_error(EventNotFound, /dummy/) }
42-
specify { expect { specification.from(none_such_id) }.to raise_error(EventNotFound, /#{none_such_id}/) }
4341
specify do
4442
repository.append_to_stream([test_record(event_id)], Stream.new("Dummy"), ExpectedVersion.none)
4543
expect { specification.stream('Another').from(event_id) }.not_to raise_error
4644
end
4745

4846
specify { expect { specification.to(nil) }.to raise_error(InvalidPageStop) }
4947
specify { expect { specification.to("") }.to raise_error(InvalidPageStop) }
50-
specify { expect { specification.to(:dummy) }.to raise_error(EventNotFound, /dummy/) }
51-
specify { expect { specification.to(none_such_id) }.to raise_error(EventNotFound, /#{none_such_id}/) }
52-
specify do
53-
repository.append_to_stream([test_record(event_id)], Stream.new("Dummy"), ExpectedVersion.none)
54-
expect { specification.stream('Another').to(event_id) }.not_to raise_error
55-
end
5648

5749
specify { expect { specification.older_than(nil) }.to raise_error(ArgumentError) }
5850
specify { expect { specification.older_than("") }.to raise_error(ArgumentError) }

0 commit comments

Comments
 (0)