Skip to content

Commit

Permalink
Validate starting and ending specification events only on execution
Browse files Browse the repository at this point in the history
No longer check if a starting or ending event exists while building
a scope. It will fail on execution anyway.
  • Loading branch information
pjurewicz authored and fidel committed Sep 4, 2023
1 parent 9c85f0c commit 067e9b7
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 31 deletions.
2 changes: 0 additions & 2 deletions ruby_event_store/lib/ruby_event_store/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def stream(stream_name)
# @return [Specification]
def from(start)
raise InvalidPageStart if start.nil? || start.empty?
raise EventNotFound.new(start) unless reader.has_event?(start)
Specification.new(reader, result.dup { |r| r.start = start })
end

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

Expand Down
6 changes: 0 additions & 6 deletions ruby_event_store/lib/ruby_event_store/specification_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ def count(specification_result)
repository.count(specification_result)
end

# @api private
# @private
def has_event?(event_id)
repository.has_event?(event_id)
end

private

attr_reader :repository, :mapper
Expand Down
19 changes: 4 additions & 15 deletions ruby_event_store/spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,6 @@ module RubyEventStore
expect { client.read.backward.stream("").limit(100).to_a }.to raise_error(IncorrectStreamData)
end

specify "raise exception if event_id does not exist" do
expect { client.read.stream("stream_name").from("0").limit(100).to_a }.to raise_error(
EventNotFound,
/Event not found: 0/
)
expect { client.read.backward.stream("stream_name").from("0").limit(100).to_a }.to raise_error(EventNotFound, /0/)
end

specify "raise exception if event_id is not given or invalid" do
expect { client.read.stream("stream_name").from(nil).limit(100).to_a }.to raise_error(InvalidPageStart)
expect { client.read.backward.stream("stream_name").from(:invalid).limit(100).to_a }.to raise_error(EventNotFound)
end

specify "fails when page size is invalid" do
expect { client.read.stream("stream_name").limit(0).to_a }.to raise_error(InvalidPageSize)
expect { client.read.backward.stream("stream_name").limit(0).to_a }.to raise_error(InvalidPageSize)
Expand Down Expand Up @@ -410,9 +397,11 @@ module RubyEventStore
client.publish(event, stream_name: "stream_name")
end

expect { client.read.stream("stream_name").from(SecureRandom.uuid).limit(100).to_a }.to raise_error(EventNotFound)
expect { client.read.stream("stream_name").from(SecureRandom.uuid).limit(100).to_a }.to raise_error(
EventNotFoundInStream
)
expect { client.read.backward.stream("stream_name").from(SecureRandom.uuid).limit(100).to_a }.to raise_error(
EventNotFound
EventNotFoundInStream
)
end

Expand Down
8 changes: 0 additions & 8 deletions ruby_event_store/spec/specification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,13 @@ module RubyEventStore

specify { expect { specification.from(nil) }.to raise_error(InvalidPageStart) }
specify { expect { specification.from("") }.to raise_error(InvalidPageStart) }
specify { expect { specification.from(:dummy) }.to raise_error(EventNotFound, /dummy/) }
specify { expect { specification.from(none_such_id) }.to raise_error(EventNotFound, /#{none_such_id}/) }
specify do
repository.append_to_stream([test_record(event_id)], Stream.new("Dummy"), ExpectedVersion.none)
expect { specification.stream('Another').from(event_id) }.not_to raise_error
end

specify { expect { specification.to(nil) }.to raise_error(InvalidPageStop) }
specify { expect { specification.to("") }.to raise_error(InvalidPageStop) }
specify { expect { specification.to(:dummy) }.to raise_error(EventNotFound, /dummy/) }
specify { expect { specification.to(none_such_id) }.to raise_error(EventNotFound, /#{none_such_id}/) }
specify do
repository.append_to_stream([test_record(event_id)], Stream.new("Dummy"), ExpectedVersion.none)
expect { specification.stream('Another').to(event_id) }.not_to raise_error
end

specify { expect { specification.older_than(nil) }.to raise_error(ArgumentError) }
specify { expect { specification.older_than("") }.to raise_error(ArgumentError) }
Expand Down

0 comments on commit 067e9b7

Please sign in to comment.