Skip to content

Commit

Permalink
Rename verify_incorrect_any_usage -> ensure_supported_any_usage
Browse files Browse the repository at this point in the history
  • Loading branch information
swistak35 committed Jul 26, 2021
1 parent 378cef3 commit 37c28d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions ruby_event_store/lib/ruby_event_store/in_memory_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ def initialize(global_position, record)
attr_accessor :record
end

def initialize(serializer: NULL, verify_incorrect_any_usage: false)
def initialize(serializer: NULL, ensure_supported_any_usage: false)
@serializer = serializer
@streams = Hash.new { |h, k| h[k] = Array.new }
@mutex = Mutex.new
@storage = Hash.new
@next_global_position = 1
@verify_incorrect_any_usage = verify_incorrect_any_usage
@ensure_supported_any_usage = ensure_supported_any_usage
end

def append_to_stream(records, stream, expected_version)
serialized_records = records.map { |record| record.serialize(serializer) }

with_synchronize(expected_version, stream) do |resolved_version|
verify_incorrect_any_usage(resolved_version, stream)
ensure_supported_any_usage(resolved_version, stream)
raise WrongExpectedEventVersion unless resolved_version.nil? || last_stream_version(stream).equal?(resolved_version)

serialized_records.each_with_index do |serialized_record, index|
Expand All @@ -54,7 +54,7 @@ def link_to_stream(event_ids, stream, expected_version)
serialized_records = event_ids.map { |id| read_event(id) }

with_synchronize(expected_version, stream) do |resolved_version|
verify_incorrect_any_usage(resolved_version, stream)
ensure_supported_any_usage(resolved_version, stream)
raise WrongExpectedEventVersion unless resolved_version.nil? || last_stream_version(stream).equal?(resolved_version)

serialized_records.each_with_index do |serialized_record, index|
Expand Down Expand Up @@ -215,8 +215,8 @@ def add_to_stream(stream, serialized_record, resolved_version, index)
streams[stream.name] << EventInStream.new(serialized_record.event_id, compute_position(resolved_version, index))
end

def verify_incorrect_any_usage(resolved_version, stream)
if @verify_incorrect_any_usage
def ensure_supported_any_usage(resolved_version, stream)
if @ensure_supported_any_usage
stream_positions = streams.fetch(stream.name, Array.new).map(&:position)
if resolved_version.nil?
raise UnsupportedVersionAnyUsage if !stream_positions.compact.empty?
Expand Down
16 changes: 8 additions & 8 deletions ruby_event_store/spec/in_memory_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module RubyEventStore
end

it 'publishing with any position to stream with specific position raise an error' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: true)
repository = InMemoryRepository.new(ensure_supported_any_usage: true)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_auto)
Expand All @@ -85,7 +85,7 @@ module RubyEventStore
end

it 'publishing with any position to stream with any position does not raise an error' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: true)
repository = InMemoryRepository.new(ensure_supported_any_usage: true)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_any)
Expand All @@ -98,7 +98,7 @@ module RubyEventStore
end

it 'publishing with specific position to stream with any position raise an error' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: true)
repository = InMemoryRepository.new(ensure_supported_any_usage: true)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_any)
Expand All @@ -111,7 +111,7 @@ module RubyEventStore
end

it 'linking with any position to stream with specific position raise an error' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: true)
repository = InMemoryRepository.new(ensure_supported_any_usage: true)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_auto)
Expand All @@ -127,7 +127,7 @@ module RubyEventStore
end

it 'linking with any position to stream with any position does not raise an error' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: true)
repository = InMemoryRepository.new(ensure_supported_any_usage: true)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_any)
Expand All @@ -143,7 +143,7 @@ module RubyEventStore
end

it 'linking with specific position to stream with any position raise an error' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: true)
repository = InMemoryRepository.new(ensure_supported_any_usage: true)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_any)
Expand All @@ -160,7 +160,7 @@ module RubyEventStore

# This test only documents the 2.x behavior
it 'publishing with any position to stream with specific position' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: false)
repository = InMemoryRepository.new(ensure_supported_any_usage: false)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_auto)
Expand All @@ -174,7 +174,7 @@ module RubyEventStore

# This test only documents the 2.x behavior
it 'publishing with specific position to stream with any position' do
repository = InMemoryRepository.new(verify_incorrect_any_usage: false)
repository = InMemoryRepository.new(ensure_supported_any_usage: false)
repository.append_to_stream([
event0 = SRecord.new,
], stream, version_any)
Expand Down

0 comments on commit 37c28d9

Please sign in to comment.