ruby_event_store 2.16.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ruby_event_store/broker.rb +11 -7
  3. data/lib/ruby_event_store/client.rb +60 -20
  4. data/lib/ruby_event_store/composed_broker.rb +65 -0
  5. data/lib/ruby_event_store/errors.rb +1 -0
  6. data/lib/ruby_event_store/in_memory_repository.rb +27 -27
  7. data/lib/ruby_event_store/instrumented_broker.rb +73 -0
  8. data/lib/ruby_event_store/instrumented_subscriptions.rb +3 -11
  9. data/lib/ruby_event_store/mappers/batch_mapper.rb +19 -0
  10. data/lib/ruby_event_store/mappers/default.rb +2 -2
  11. data/lib/ruby_event_store/mappers/encryption_key.rb +8 -1
  12. data/lib/ruby_event_store/mappers/encryption_mapper.rb +2 -2
  13. data/lib/ruby_event_store/mappers/instrumented_batch_mapper.rb +28 -0
  14. data/lib/ruby_event_store/mappers/transformation/domain_event.rb +8 -10
  15. data/lib/ruby_event_store/mappers/transformation/encryption.rb +2 -3
  16. data/lib/ruby_event_store/mappers/transformation/event_class_remapper.rb +1 -1
  17. data/lib/ruby_event_store/mappers/transformation/preserve_types.rb +11 -19
  18. data/lib/ruby_event_store/mappers/transformation/stringify_metadata_keys.rb +1 -1
  19. data/lib/ruby_event_store/mappers/transformation/symbolize_metadata_keys.rb +1 -1
  20. data/lib/ruby_event_store/record.rb +9 -10
  21. data/lib/ruby_event_store/serialized_record.rb +2 -2
  22. data/lib/ruby_event_store/spec/broker_lint.rb +27 -10
  23. data/lib/ruby_event_store/spec/dispatcher_lint.rb +1 -1
  24. data/lib/ruby_event_store/spec/event_lint.rb +3 -3
  25. data/lib/ruby_event_store/spec/event_repository_lint.rb +228 -189
  26. data/lib/ruby_event_store/spec/mapper_lint.rb +2 -2
  27. data/lib/ruby_event_store/spec/scheduler_lint.rb +1 -1
  28. data/lib/ruby_event_store/spec/subscriptions_lint.rb +21 -20
  29. data/lib/ruby_event_store/specification.rb +5 -5
  30. data/lib/ruby_event_store/specification_reader.rb +6 -2
  31. data/lib/ruby_event_store/specification_result.rb +32 -34
  32. data/lib/ruby_event_store/subscriptions.rb +20 -20
  33. data/lib/ruby_event_store/transform_keys.rb +1 -3
  34. data/lib/ruby_event_store/version.rb +1 -1
  35. data/lib/ruby_event_store.rb +5 -1
  36. metadata +7 -3
@@ -17,7 +17,7 @@ module RubyEventStore
17
17
  metadata: metadata,
18
18
  event_type: event_type,
19
19
  timestamp: timestamp.round(TIMESTAMP_PRECISION),
20
- valid_at: (valid_at || timestamp).round(TIMESTAMP_PRECISION)
20
+ valid_at: (valid_at || timestamp).round(TIMESTAMP_PRECISION),
21
21
  )
22
22
  end
23
23
  end
@@ -33,14 +33,14 @@ module RubyEventStore
33
33
  end
34
34
 
35
35
  module RubyEventStore
36
- ::RSpec.shared_examples :event_repository do |mk_repository, helper|
36
+ ::RSpec.shared_examples "event repository" do |mk_repository, helper|
37
37
  let(:repository) { mk_repository.call }
38
38
  let(:specification) { Specification.new(SpecificationReader.new(repository, Mappers::Default.new)) }
39
39
  let(:global_stream) { Stream.new(GLOBAL_STREAM) }
40
40
  let(:stream) { Stream.new(SecureRandom.uuid) }
41
41
  let(:stream_flow) { Stream.new("flow") }
42
42
  let(:stream_other) { Stream.new("other") }
43
-
43
+
44
44
  let(:version_none) { ExpectedVersion.none }
45
45
  let(:version_auto) { ExpectedVersion.auto }
46
46
  let(:version_any) { ExpectedVersion.any }
@@ -76,9 +76,11 @@ module RubyEventStore
76
76
  end
77
77
 
78
78
  specify "append_to_stream returns self" do
79
- repository
80
- .append_to_stream([event = SRecord.new], stream, version_none)
81
- .append_to_stream([event = SRecord.new], stream, version_0)
79
+ repository.append_to_stream([SRecord.new], stream, version_none).append_to_stream(
80
+ [SRecord.new],
81
+ stream,
82
+ version_0,
83
+ )
82
84
  end
83
85
 
84
86
  specify "link_to_stream returns self" do
@@ -98,9 +100,11 @@ module RubyEventStore
98
100
  end
99
101
 
100
102
  specify "links an initial event to a new stream" do
101
- repository
102
- .append_to_stream([event = SRecord.new], stream, version_none)
103
- .link_to_stream([event.event_id], stream_flow, version_none)
103
+ repository.append_to_stream([event = SRecord.new], stream, version_none).link_to_stream(
104
+ [event.event_id],
105
+ stream_flow,
106
+ version_none,
107
+ )
104
108
 
105
109
  expect(read_events_forward(repository, count: 1).first).to eq(event)
106
110
  expect(read_events_forward(repository, stream).first).to eq(event)
@@ -115,9 +119,11 @@ module RubyEventStore
115
119
  end
116
120
 
117
121
  specify "links multiple initial events to a new stream" do
118
- repository
119
- .append_to_stream([event0 = SRecord.new, event1 = SRecord.new], stream, version_none)
120
- .link_to_stream([event0.event_id, event1.event_id], stream_flow, version_none)
122
+ repository.append_to_stream([event0 = SRecord.new, event1 = SRecord.new], stream, version_none).link_to_stream(
123
+ [event0.event_id, event1.event_id],
124
+ stream_flow,
125
+ version_none,
126
+ )
121
127
  expect(read_events_forward(repository, count: 2)).to eq([event0, event1])
122
128
  expect(read_events_forward(repository, stream_flow)).to eq([event0, event1])
123
129
  end
@@ -140,9 +146,9 @@ module RubyEventStore
140
146
 
141
147
  specify "incorrect expected version on second write" do
142
148
  repository.append_to_stream([event0 = SRecord.new, event1 = SRecord.new], stream, version_none)
143
- expect do
144
- repository.append_to_stream([event2 = SRecord.new, event3 = SRecord.new], stream, version_0)
145
- end.to raise_error(WrongExpectedEventVersion)
149
+ expect do repository.append_to_stream([SRecord.new, SRecord.new], stream, version_0) end.to raise_error(
150
+ WrongExpectedEventVersion,
151
+ )
146
152
 
147
153
  expect(read_events_forward(repository, count: 4)).to eq([event0, event1])
148
154
  expect(read_events_forward(repository, stream)).to eq([event0, event1])
@@ -152,7 +158,7 @@ module RubyEventStore
152
158
  repository.append_to_stream([event0 = SRecord.new, event1 = SRecord.new], stream, version_none)
153
159
  repository.append_to_stream([event2 = SRecord.new, event3 = SRecord.new], stream_other, version_none)
154
160
  expect { repository.link_to_stream([event2.event_id, event3.event_id], stream, version_0) }.to raise_error(
155
- WrongExpectedEventVersion
161
+ WrongExpectedEventVersion,
156
162
  )
157
163
 
158
164
  expect(read_events_forward(repository, count: 4)).to eq([event0, event1, event2, event3])
@@ -161,8 +167,8 @@ module RubyEventStore
161
167
 
162
168
  specify ":none on first and subsequent write" do
163
169
  repository.append_to_stream([eventA = SRecord.new], stream, version_none)
164
- expect { repository.append_to_stream([eventB = SRecord.new], stream, version_none) }.to raise_error(
165
- WrongExpectedEventVersion
170
+ expect { repository.append_to_stream([SRecord.new], stream, version_none) }.to raise_error(
171
+ WrongExpectedEventVersion,
166
172
  )
167
173
  expect(read_events_forward(repository, count: 1)).to eq([eventA])
168
174
  expect(read_events_forward(repository, stream)).to eq([eventA])
@@ -173,7 +179,7 @@ module RubyEventStore
173
179
 
174
180
  repository.link_to_stream([eventA.event_id], stream_flow, version_none)
175
181
  expect { repository.link_to_stream([eventB.event_id], stream_flow, version_none) }.to raise_error(
176
- WrongExpectedEventVersion
182
+ WrongExpectedEventVersion,
177
183
  )
178
184
 
179
185
  expect(read_events_forward(repository, count: 1)).to eq([eventA])
@@ -191,7 +197,7 @@ module RubyEventStore
191
197
  repository.append_to_stream(
192
198
  [event0 = SRecord.new, event1 = SRecord.new, event2 = SRecord.new, event3 = SRecord.new],
193
199
  stream,
194
- version_any
200
+ version_any,
195
201
  )
196
202
 
197
203
  repository.link_to_stream([event0.event_id, event1.event_id], stream_flow, version_any)
@@ -202,37 +208,33 @@ module RubyEventStore
202
208
  end
203
209
 
204
210
  specify ":auto queries for last position in given stream" do
205
- repository.append_to_stream(
206
- [eventA = SRecord.new, eventB = SRecord.new, eventC = SRecord.new],
207
- stream_other,
208
- version_auto
209
- )
210
- repository.append_to_stream([event0 = SRecord.new, event1 = SRecord.new], stream, version_auto)
211
- repository.append_to_stream([event2 = SRecord.new, event3 = SRecord.new], stream, version_1)
211
+ repository.append_to_stream([SRecord.new, SRecord.new, SRecord.new], stream_other, version_auto)
212
+ repository.append_to_stream([SRecord.new, SRecord.new], stream, version_auto)
213
+ repository.append_to_stream([SRecord.new, SRecord.new], stream, version_1)
212
214
  end
213
215
 
214
216
  specify ":auto queries for last position in given stream when linking" do
215
217
  repository.append_to_stream(
216
218
  [eventA = SRecord.new, eventB = SRecord.new, eventC = SRecord.new],
217
219
  stream_other,
218
- version_auto
220
+ version_auto,
219
221
  )
220
- repository.append_to_stream([event0 = SRecord.new, event1 = SRecord.new], stream, version_auto)
222
+ repository.append_to_stream([SRecord.new, SRecord.new], stream, version_auto)
221
223
  repository.link_to_stream([eventA.event_id, eventB.event_id, eventC.event_id], stream, version_1)
222
224
  end
223
225
 
224
226
  specify ":auto starts from 0" do
225
- repository.append_to_stream([event0 = SRecord.new], stream, version_auto)
226
- expect { repository.append_to_stream([event1 = SRecord.new], stream, version_none) }.to raise_error(
227
- WrongExpectedEventVersion
227
+ repository.append_to_stream([SRecord.new], stream, version_auto)
228
+ expect { repository.append_to_stream([SRecord.new], stream, version_none) }.to raise_error(
229
+ WrongExpectedEventVersion,
228
230
  )
229
231
  end
230
232
 
231
233
  specify ":auto linking starts from 0" do
232
234
  repository.append_to_stream([event0 = SRecord.new], stream_other, version_auto)
233
235
  repository.link_to_stream([event0.event_id], stream, version_auto)
234
- expect { repository.append_to_stream([event1 = SRecord.new], stream, version_none) }.to raise_error(
235
- WrongExpectedEventVersion
236
+ expect { repository.append_to_stream([SRecord.new], stream, version_none) }.to raise_error(
237
+ WrongExpectedEventVersion,
236
238
  )
237
239
  end
238
240
 
@@ -249,7 +251,7 @@ module RubyEventStore
249
251
  repository.append_to_stream(
250
252
  [event0 = SRecord.new, event1 = SRecord.new, event2 = SRecord.new, event3 = SRecord.new],
251
253
  stream,
252
- version_auto
254
+ version_auto,
253
255
  )
254
256
  repository.link_to_stream([event0.event_id, event1.event_id], stream_flow, version_auto)
255
257
  repository.link_to_stream([event2.event_id, event3.event_id], stream_flow, version_auto)
@@ -311,7 +313,7 @@ module RubyEventStore
311
313
  end
312
314
  wait_for_it = false
313
315
  threads.each(&:join)
314
- expect(fail_occurred).to eq(false)
316
+ expect(fail_occurred).to be(false)
315
317
  expect(read_events_forward(repository, stream).size).to eq(400)
316
318
  events_in_stream = read_events_forward(repository, stream)
317
319
  expect(events_in_stream.size).to eq(400)
@@ -351,7 +353,7 @@ module RubyEventStore
351
353
  end
352
354
  wait_for_it = false
353
355
  threads.each(&:join)
354
- expect(fail_occurred).to eq(false)
356
+ expect(fail_occurred).to be(false)
355
357
  expect(read_events_forward(repository, stream_flow).size).to eq(400)
356
358
  events_in_stream = read_events_forward(repository, stream_flow)
357
359
  expect(events_in_stream.size).to eq(400)
@@ -475,9 +477,11 @@ module RubyEventStore
475
477
 
476
478
  it "data and metadata attributes are retrieved when linking" do
477
479
  event = SRecord.new(data: { "order_id" => 3 }, metadata: { "request_id" => 4 })
478
- repository
479
- .append_to_stream([event], stream, version_any)
480
- .link_to_stream([event.event_id], stream_flow, version_any)
480
+ repository.append_to_stream([event], stream, version_any).link_to_stream(
481
+ [event.event_id],
482
+ stream_flow,
483
+ version_any,
484
+ )
481
485
  retrieved_event = read_events_forward(repository, stream_flow).first
482
486
  expect(retrieved_event.metadata).to eq({ "request_id" => 4 })
483
487
  expect(retrieved_event.data).to eq({ "order_id" => 3 })
@@ -495,9 +499,11 @@ module RubyEventStore
495
499
  end
496
500
 
497
501
  it "does not have deleted streams with linked events" do
498
- repository
499
- .append_to_stream([e1 = SRecord.new], stream, version_none)
500
- .link_to_stream([e1.event_id], stream_flow, version_none)
502
+ repository.append_to_stream([e1 = SRecord.new], stream, version_none).link_to_stream(
503
+ [e1.event_id],
504
+ stream_flow,
505
+ version_none,
506
+ )
501
507
 
502
508
  repository.delete_stream(stream_flow)
503
509
  expect(read_events_forward(repository, stream_flow)).to be_empty
@@ -508,13 +514,13 @@ module RubyEventStore
508
514
  just_an_id = "d5c134c2-db65-4e87-b6ea-d196f8f1a292"
509
515
  repository.append_to_stream([SRecord.new(event_id: just_an_id)], stream, version_none)
510
516
 
511
- expect(repository.has_event?(just_an_id)).to be_truthy
512
- expect(repository.has_event?(just_an_id.clone)).to be_truthy
517
+ expect(repository).to have_event(just_an_id)
518
+ expect(repository).to have_event(just_an_id.clone)
513
519
  expect(repository.has_event?("any other id")).to be false
514
520
 
515
521
  repository.delete_stream(stream)
516
- expect(repository.has_event?(just_an_id)).to be_truthy
517
- expect(repository.has_event?(just_an_id.clone)).to be_truthy
522
+ expect(repository).to have_event(just_an_id)
523
+ expect(repository).to have_event(just_an_id.clone)
518
524
  end
519
525
 
520
526
  it "#position_in_stream happy path" do
@@ -547,7 +553,7 @@ module RubyEventStore
547
553
  skip unless helper.supports_position_queries?
548
554
  repository.append_to_stream([event0 = SRecord.new], stream, version_any)
549
555
 
550
- expect(repository.position_in_stream(event0.event_id, stream)).to eq(nil)
556
+ expect(repository.position_in_stream(event0.event_id, stream)).to be_nil
551
557
  end
552
558
 
553
559
  it "#global_position happy path" do
@@ -573,14 +579,14 @@ module RubyEventStore
573
579
  repository.append_to_stream([SRecord.new], stream, version_any)
574
580
  just_an_id = "d5c134c2-db65-4e87-b6ea-d196f8f1a292"
575
581
 
576
- expect(repository.event_in_stream?(just_an_id, stream)).to eq(false)
582
+ expect(repository.event_in_stream?(just_an_id, stream)).to be(false)
577
583
  end
578
584
 
579
585
  it "#event_in_stream? when event published into stream" do
580
586
  skip unless helper.supports_event_in_stream_query?
581
587
  repository.append_to_stream([event0 = SRecord.new], stream, version_any)
582
588
 
583
- expect(repository.event_in_stream?(event0.event_id, stream)).to eq(true)
589
+ expect(repository.event_in_stream?(event0.event_id, stream)).to be(true)
584
590
  end
585
591
 
586
592
  it "#event_in_stream? when event not linked into stream" do
@@ -588,7 +594,7 @@ module RubyEventStore
588
594
  repository.append_to_stream([SRecord.new], stream_flow, version_any)
589
595
  repository.append_to_stream([event1 = SRecord.new], stream, version_any)
590
596
 
591
- expect(repository.event_in_stream?(event1.event_id, stream_flow)).to eq(false)
597
+ expect(repository.event_in_stream?(event1.event_id, stream_flow)).to be(false)
592
598
  end
593
599
 
594
600
  it "#event_in_stream? when event linked into stream" do
@@ -596,26 +602,22 @@ module RubyEventStore
596
602
  repository.append_to_stream([event0 = SRecord.new], stream, version_any)
597
603
  repository.link_to_stream([event0.event_id], stream_flow, version_any)
598
604
 
599
- expect(repository.event_in_stream?(event0.event_id, stream_flow)).to eq(true)
605
+ expect(repository.event_in_stream?(event0.event_id, stream_flow)).to be(true)
600
606
  end
601
607
 
602
608
  it "#event_in_stream? when stream is empty" do
603
609
  skip unless helper.supports_event_in_stream_query?
604
610
  just_an_id = "d5c134c2-db65-4e87-b6ea-d196f8f1a292"
605
611
 
606
- expect(repository.event_in_stream?(just_an_id, stream)).to eq(false)
612
+ expect(repository.event_in_stream?(just_an_id, stream)).to be(false)
607
613
  end
608
614
 
609
615
  it "knows last event in stream" do
610
- repository.append_to_stream(
611
- [a = SRecord.new(event_id: "00000000-0000-0000-0000-000000000001")],
612
- stream,
613
- version_none
614
- )
616
+ repository.append_to_stream([SRecord.new(event_id: "00000000-0000-0000-0000-000000000001")], stream, version_none)
615
617
  repository.append_to_stream(
616
618
  [b = SRecord.new(event_id: "00000000-0000-0000-0000-000000000002")],
617
619
  stream,
618
- version_0
620
+ version_0,
619
621
  )
620
622
 
621
623
  expect(repository.last_stream_event(stream)).to eq(b)
@@ -623,16 +625,14 @@ module RubyEventStore
623
625
  end
624
626
 
625
627
  it "knows last event in stream when linked" do
626
- repository
627
- .append_to_stream(
628
- [
629
- e0 = SRecord.new(event_id: "00000000-0000-0000-0000-000000000001"),
630
- e1 = SRecord.new(event_id: "00000000-0000-0000-0000-000000000002")
631
- ],
632
- stream,
633
- version_none
634
- )
635
- .link_to_stream([e1.event_id, e0.event_id], stream_flow, version_none)
628
+ repository.append_to_stream(
629
+ [
630
+ e0 = SRecord.new(event_id: "00000000-0000-0000-0000-000000000001"),
631
+ e1 = SRecord.new(event_id: "00000000-0000-0000-0000-000000000002"),
632
+ ],
633
+ stream,
634
+ version_none,
635
+ ).link_to_stream([e1.event_id, e0.event_id], stream_flow, version_none)
636
636
  expect(repository.last_stream_event(stream_flow)).to eq(e0)
637
637
  end
638
638
 
@@ -667,10 +667,10 @@ module RubyEventStore
667
667
  expect(read_events_backward(repository, stream, count: 3)).to eq(events.last(3).reverse)
668
668
  expect(read_events_backward(repository, stream, count: 100)).to eq(events.reverse)
669
669
  expect(read_events_backward(repository, stream, from: events[4].event_id, count: 4)).to eq(
670
- events.first(4).reverse
670
+ events.first(4).reverse,
671
671
  )
672
672
  expect(read_events_backward(repository, stream, from: events[4].event_id, count: 100)).to eq(
673
- events.first(4).reverse
673
+ events.first(4).reverse,
674
674
  )
675
675
  expect(read_events_backward(repository, stream, to: events[4].event_id, count: 4)).to eq(events.last(4).reverse)
676
676
  expect(read_events_backward(repository, stream, to: events[4].event_id, count: 100)).to eq(events.last(5).reverse)
@@ -692,9 +692,11 @@ module RubyEventStore
692
692
  ].map { |id| SRecord.new(event_id: id) }
693
693
  repository.append_to_stream([SRecord.new], stream_other, version_none)
694
694
  events.each.with_index do |event, index|
695
- repository
696
- .append_to_stream([event], stream, ExpectedVersion.new(index - 1))
697
- .link_to_stream([event.event_id], stream_flow, ExpectedVersion.new(index - 1))
695
+ repository.append_to_stream([event], stream, ExpectedVersion.new(index - 1)).link_to_stream(
696
+ [event.event_id],
697
+ stream_flow,
698
+ ExpectedVersion.new(index - 1),
699
+ )
698
700
  end
699
701
  repository.append_to_stream([SRecord.new], stream_other, version_0)
700
702
 
@@ -708,16 +710,16 @@ module RubyEventStore
708
710
  expect(read_events_backward(repository, stream_flow, count: 3)).to eq(events.last(3).reverse)
709
711
  expect(read_events_backward(repository, stream_flow, count: 100)).to eq(events.reverse)
710
712
  expect(read_events_backward(repository, stream_flow, from: events[4].event_id, count: 4)).to eq(
711
- events.first(4).reverse
713
+ events.first(4).reverse,
712
714
  )
713
715
  expect(read_events_backward(repository, stream_flow, from: events[4].event_id, count: 100)).to eq(
714
- events.first(4).reverse
716
+ events.first(4).reverse,
715
717
  )
716
718
  expect(read_events_backward(repository, stream_flow, to: events[4].event_id, count: 4)).to eq(
717
- events[6..9].reverse
719
+ events[6..9].reverse,
718
720
  )
719
721
  expect(read_events_backward(repository, stream_flow, to: events[4].event_id, count: 100)).to eq(
720
- events[5..9].reverse
722
+ events[5..9].reverse,
721
723
  )
722
724
  end
723
725
 
@@ -726,10 +728,10 @@ module RubyEventStore
726
728
  s2 = stream_other
727
729
  repository
728
730
  .append_to_stream([a = SRecord.new(event_id: "7010d298-ab69-4bb1-9251-f3466b5d1282")], s1, version_none)
729
- .append_to_stream([b = SRecord.new(event_id: "34f88aca-aaba-4ca0-9256-8017b47528c5")], s2, version_none)
731
+ .append_to_stream([SRecord.new(event_id: "34f88aca-aaba-4ca0-9256-8017b47528c5")], s2, version_none)
730
732
  .append_to_stream([c = SRecord.new(event_id: "8e61c864-ceae-4684-8726-97c34eb8fc4f")], s1, version_0)
731
- .append_to_stream([d = SRecord.new(event_id: "30963ed9-6349-450b-ac9b-8ea50115b3bd")], s2, version_0)
732
- .append_to_stream([e = SRecord.new(event_id: "5bdc58b7-e8a7-4621-afd6-ccb828d72457")], s2, version_1)
733
+ .append_to_stream([SRecord.new(event_id: "30963ed9-6349-450b-ac9b-8ea50115b3bd")], s2, version_0)
734
+ .append_to_stream([SRecord.new(event_id: "5bdc58b7-e8a7-4621-afd6-ccb828d72457")], s2, version_1)
733
735
 
734
736
  expect(read_events_forward(repository, s1)).to eq [a, c]
735
737
  expect(read_events_backward(repository, s1)).to eq [c, a]
@@ -739,10 +741,10 @@ module RubyEventStore
739
741
  s1, fs1, fs2 = stream, stream_flow, stream_other
740
742
  repository
741
743
  .append_to_stream([a = SRecord.new(event_id: "7010d298-ab69-4bb1-9251-f3466b5d1282")], s1, version_none)
742
- .append_to_stream([b = SRecord.new(event_id: "34f88aca-aaba-4ca0-9256-8017b47528c5")], s1, version_0)
744
+ .append_to_stream([SRecord.new(event_id: "34f88aca-aaba-4ca0-9256-8017b47528c5")], s1, version_0)
743
745
  .append_to_stream([c = SRecord.new(event_id: "8e61c864-ceae-4684-8726-97c34eb8fc4f")], s1, version_1)
744
- .append_to_stream([d = SRecord.new(event_id: "30963ed9-6349-450b-ac9b-8ea50115b3bd")], s1, version_2)
745
- .append_to_stream([e = SRecord.new(event_id: "5bdc58b7-e8a7-4621-afd6-ccb828d72457")], s1, version_3)
746
+ .append_to_stream([SRecord.new(event_id: "30963ed9-6349-450b-ac9b-8ea50115b3bd")], s1, version_2)
747
+ .append_to_stream([SRecord.new(event_id: "5bdc58b7-e8a7-4621-afd6-ccb828d72457")], s1, version_3)
746
748
  .link_to_stream(["7010d298-ab69-4bb1-9251-f3466b5d1282"], fs1, version_none)
747
749
  .link_to_stream(["34f88aca-aaba-4ca0-9256-8017b47528c5"], fs2, version_none)
748
750
  .link_to_stream(["8e61c864-ceae-4684-8726-97c34eb8fc4f"], fs1, version_0)
@@ -799,9 +801,11 @@ module RubyEventStore
799
801
  868cac42-3d19-4b39-84e8-cd32d65c2445
800
802
  ].map { |id| SRecord.new(event_id: id) }
801
803
  events.each do |ev|
802
- repository
803
- .append_to_stream([ev], Stream.new(SecureRandom.uuid), version_none)
804
- .link_to_stream([ev.event_id], Stream.new(SecureRandom.uuid), version_none)
804
+ repository.append_to_stream([ev], Stream.new(SecureRandom.uuid), version_none).link_to_stream(
805
+ [ev.event_id],
806
+ Stream.new(SecureRandom.uuid),
807
+ version_none,
808
+ )
805
809
  end
806
810
 
807
811
  expect(read_events_forward(repository, count: 3)).to eq(events.first(3))
@@ -830,21 +834,21 @@ module RubyEventStore
830
834
  expect(read_events_forward(repository, from: "96c920b1-cdd0-40f4-907c-861b9fff7d02")).to eq([events.last])
831
835
  expect(read_events_backward(repository, from: "56404f79-0ba0-4aa0-8524-dc3436368ca0")).to eq([events.first])
832
836
  expect(read_events_forward(repository, to: "56404f79-0ba0-4aa0-8524-dc3436368ca0", count: 1)).to eq(
833
- [events.first]
837
+ [events.first],
834
838
  )
835
839
  expect(read_events_backward(repository, to: "96c920b1-cdd0-40f4-907c-861b9fff7d02", count: 1)).to eq(
836
- [events.last]
840
+ [events.last],
837
841
  )
838
842
 
839
843
  expect(read_events_forward(repository, stream, from: "96c920b1-cdd0-40f4-907c-861b9fff7d02")).to eq([events.last])
840
844
  expect(read_events_backward(repository, stream, from: "56404f79-0ba0-4aa0-8524-dc3436368ca0")).to eq(
841
- [events.first]
845
+ [events.first],
842
846
  )
843
847
  expect(read_events_forward(repository, stream, to: "56404f79-0ba0-4aa0-8524-dc3436368ca0", count: 1)).to eq(
844
- [events.first]
848
+ [events.first],
845
849
  )
846
850
  expect(read_events_backward(repository, stream, to: "96c920b1-cdd0-40f4-907c-861b9fff7d02", count: 1)).to eq(
847
- [events.last]
851
+ [events.last],
848
852
  )
849
853
  end
850
854
 
@@ -861,15 +865,17 @@ module RubyEventStore
861
865
  repository.append_to_stream(
862
866
  [SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef")],
863
867
  stream_other,
864
- version_none
868
+ version_none,
865
869
  )
866
870
  end.to raise_error(EventDuplicatedInStream)
867
871
  end
868
872
 
869
873
  it "does not allow linking same event twice in a stream" do
870
- repository
871
- .append_to_stream([SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef")], stream, version_none)
872
- .link_to_stream(["a1b49edb-7636-416f-874a-88f94b859bef"], stream_flow, version_none)
874
+ repository.append_to_stream(
875
+ [SRecord.new(event_id: "a1b49edb-7636-416f-874a-88f94b859bef")],
876
+ stream,
877
+ version_none,
878
+ ).link_to_stream(["a1b49edb-7636-416f-874a-88f94b859bef"], stream_flow, version_none)
873
879
  expect do
874
880
  repository.link_to_stream(["a1b49edb-7636-416f-874a-88f94b859bef"], stream_flow, version_0)
875
881
  end.to raise_error(EventDuplicatedInStream)
@@ -889,7 +895,7 @@ module RubyEventStore
889
895
  repository.append_to_stream(
890
896
  [SRecord.new(event_id: "9bedf448-e4d0-41a3-a8cd-f94aec7aa763")],
891
897
  stream,
892
- version_none
898
+ version_none,
893
899
  )
894
900
  end.to raise_error(WrongExpectedEventVersion)
895
901
  expect(repository.has_event?("9bedf448-e4d0-41a3-a8cd-f94aec7aa763")).to be false
@@ -906,25 +912,25 @@ module RubyEventStore
906
912
  end
907
913
 
908
914
  specify "read returns enumerator" do
909
- expect(repository.read(specification.result)).to be_kind_of(Enumerator)
915
+ expect(repository.read(specification.result)).to be_a(Enumerator)
910
916
  end
911
917
 
912
918
  specify "can store arbitrary binary data" do
913
919
  skip unless helper.supports_binary?
914
- binary = String.new("\xB0").force_encoding("binary")
920
+ binary = (+"\xB0").force_encoding("binary")
915
921
 
916
- repository.append_to_stream([event = SRecord.new(data: binary, metadata: binary)], stream, version_none)
922
+ repository.append_to_stream([SRecord.new(data: binary, metadata: binary)], stream, version_none)
917
923
  end
918
924
 
919
925
  specify do
920
- expect(repository.read(specification.in_batches.result)).to be_kind_of(Enumerator)
921
- expect(repository.read(specification.in_batches.as_at.result)).to be_kind_of(Enumerator)
922
- expect(repository.read(specification.in_batches.as_of.result)).to be_kind_of(Enumerator)
926
+ expect(repository.read(specification.in_batches.result)).to be_a(Enumerator)
927
+ expect(repository.read(specification.in_batches.as_at.result)).to be_a(Enumerator)
928
+ expect(repository.read(specification.in_batches.as_of.result)).to be_a(Enumerator)
923
929
  events = Array.new(10) { SRecord.new }
924
930
  repository.append_to_stream(events, Stream.new("Dummy"), ExpectedVersion.none)
925
- expect(repository.read(specification.in_batches.result)).to be_kind_of(Enumerator)
926
- expect(repository.read(specification.in_batches.as_at.result)).to be_kind_of(Enumerator)
927
- expect(repository.read(specification.in_batches.as_of.result)).to be_kind_of(Enumerator)
931
+ expect(repository.read(specification.in_batches.result)).to be_a(Enumerator)
932
+ expect(repository.read(specification.in_batches.as_at.result)).to be_a(Enumerator)
933
+ expect(repository.read(specification.in_batches.as_of.result)).to be_a(Enumerator)
928
934
  end
929
935
 
930
936
  specify do
@@ -972,7 +978,7 @@ module RubyEventStore
972
978
  repository.append_to_stream(
973
979
  events,
974
980
  RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
975
- RubyEventStore::ExpectedVersion.any
981
+ RubyEventStore::ExpectedVersion.any,
976
982
  )
977
983
 
978
984
  batches = repository.read(specification.as_at.forward.limit(101).in_batches.result).to_a
@@ -1056,35 +1062,39 @@ module RubyEventStore
1056
1062
 
1057
1063
  specify do
1058
1064
  event = SRecord.new
1059
- repository.append_to_stream([event], Stream.new('dummy'), ExpectedVersion.any)
1060
- expect do
1061
- repository.read(specification.stream('another').from(event.event_id).result).to_a
1062
- end.to raise_error(RubyEventStore::EventNotFound, "Event not found: #{event.event_id}")
1065
+ repository.append_to_stream([event], Stream.new("dummy"), ExpectedVersion.any)
1066
+ expect do repository.read(specification.stream("another").from(event.event_id).result).to_a end.to raise_error(
1067
+ RubyEventStore::EventNotFound,
1068
+ "Event not found: #{event.event_id}",
1069
+ )
1063
1070
  end
1064
1071
 
1065
1072
  specify do
1066
1073
  event = SRecord.new
1067
- repository.append_to_stream([event], Stream.new('dummy'), ExpectedVersion.any)
1068
- expect do
1069
- repository.read(specification.stream('another').to(event.event_id).result).to_a
1070
- end.to raise_error(RubyEventStore::EventNotFound, "Event not found: #{event.event_id}")
1074
+ repository.append_to_stream([event], Stream.new("dummy"), ExpectedVersion.any)
1075
+ expect do repository.read(specification.stream("another").to(event.event_id).result).to_a end.to raise_error(
1076
+ RubyEventStore::EventNotFound,
1077
+ "Event not found: #{event.event_id}",
1078
+ )
1071
1079
  end
1072
1080
 
1073
1081
  specify do
1074
1082
  not_existing_uuid = SecureRandom.uuid
1075
- expect do
1076
- repository.read(specification.from(not_existing_uuid).result).to_a
1077
- end.to raise_error(RubyEventStore::EventNotFound, "Event not found: #{not_existing_uuid}")
1083
+ expect do repository.read(specification.from(not_existing_uuid).result).to_a end.to raise_error(
1084
+ RubyEventStore::EventNotFound,
1085
+ "Event not found: #{not_existing_uuid}",
1086
+ )
1078
1087
  end
1079
1088
 
1080
1089
  specify do
1081
1090
  not_existing_uuid = SecureRandom.uuid
1082
- expect do
1083
- repository.read(specification.to(not_existing_uuid).result).to_a
1084
- end.to raise_error(RubyEventStore::EventNotFound, "Event not found: #{not_existing_uuid}")
1091
+ expect do repository.read(specification.to(not_existing_uuid).result).to_a end.to raise_error(
1092
+ RubyEventStore::EventNotFound,
1093
+ "Event not found: #{not_existing_uuid}",
1094
+ )
1085
1095
  end
1086
1096
 
1087
- context "#update_messages" do
1097
+ describe "#update_messages" do
1088
1098
  specify "changes events" do
1089
1099
  skip unless helper.supports_upsert?
1090
1100
  events = Array.new(5) { SRecord.new }
@@ -1098,27 +1108,27 @@ module RubyEventStore
1098
1108
  data: events[0].data,
1099
1109
  metadata: events[0].metadata,
1100
1110
  event_type: events[0].event_type,
1101
- timestamp: events[0].timestamp
1111
+ timestamp: events[0].timestamp,
1102
1112
  ),
1103
1113
  b =
1104
1114
  SRecord.new(
1105
1115
  event_id: events[1].event_id.dup,
1106
1116
  data: {
1107
- "test" => 1
1117
+ "test" => 1,
1108
1118
  },
1109
1119
  metadata: events[1].metadata,
1110
1120
  event_type: events[1].event_type,
1111
- timestamp: events[1].timestamp
1121
+ timestamp: events[1].timestamp,
1112
1122
  ),
1113
1123
  c =
1114
1124
  SRecord.new(
1115
1125
  event_id: events[2].event_id,
1116
1126
  data: events[2].data,
1117
1127
  metadata: {
1118
- "test" => 2
1128
+ "test" => 2,
1119
1129
  },
1120
1130
  event_type: events[2].event_type,
1121
- timestamp: events[2].timestamp
1131
+ timestamp: events[2].timestamp,
1122
1132
  ),
1123
1133
  d =
1124
1134
  SRecord.new(
@@ -1126,21 +1136,21 @@ module RubyEventStore
1126
1136
  data: events[3].data,
1127
1137
  metadata: events[3].metadata,
1128
1138
  event_type: "event_type3",
1129
- timestamp: events[3].timestamp
1139
+ timestamp: events[3].timestamp,
1130
1140
  ),
1131
1141
  e =
1132
1142
  SRecord.new(
1133
1143
  event_id: events[4].event_id.dup,
1134
1144
  data: {
1135
- "test" => 4
1145
+ "test" => 4,
1136
1146
  },
1137
1147
  metadata: {
1138
- "test" => 42
1148
+ "test" => 42,
1139
1149
  },
1140
1150
  event_type: "event_type4",
1141
- timestamp: events[4].timestamp
1142
- )
1143
- ]
1151
+ timestamp: events[4].timestamp,
1152
+ ),
1153
+ ],
1144
1154
  )
1145
1155
 
1146
1156
  expect(repository.read(specification.result).to_a).to eq([a, b, c, d, e])
@@ -1192,39 +1202,39 @@ module RubyEventStore
1192
1202
  repository.append_to_stream([e1, e2, e3], stream, version_any)
1193
1203
 
1194
1204
  expect(repository.read(specification.with_id(["8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea"]).read_first.result)).to eq(
1195
- e1
1205
+ e1,
1196
1206
  )
1197
1207
  expect(repository.read(specification.with_id(["d345f86d-b903-4d78-803f-38990c078d9e"]).read_first.result)).to eq(
1198
- e3
1199
- )
1200
- expect(repository.read(specification.with_id(["c31b327c-0da1-4178-a3cd-d2f6bb5d0688"]).read_first.result)).to eq(
1201
- nil
1208
+ e3,
1202
1209
  )
1210
+ expect(
1211
+ repository.read(specification.with_id(["c31b327c-0da1-4178-a3cd-d2f6bb5d0688"]).read_first.result),
1212
+ ).to be_nil
1203
1213
  expect(
1204
1214
  repository.read(
1205
1215
  specification
1206
1216
  .with_id(%w[8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea d345f86d-b903-4d78-803f-38990c078d9e])
1207
1217
  .in_batches
1208
- .result
1218
+ .result,
1209
1219
  ).to_a[
1210
1220
  0
1211
- ]
1221
+ ],
1212
1222
  ).to eq([e1, e3])
1213
1223
  expect(
1214
1224
  repository.read(
1215
- specification.stream("Stream A").with_id(["8cee1139-4f96-483a-a175-2b947283c3c7"]).read_first.result
1216
- )
1225
+ specification.stream("Stream A").with_id(["8cee1139-4f96-483a-a175-2b947283c3c7"]).read_first.result,
1226
+ ),
1217
1227
  ).to eq(e2)
1218
1228
  expect(
1219
1229
  repository.read(
1220
- specification.stream("Stream B").with_id(["8cee1139-4f96-483a-a175-2b947283c3c7"]).read_first.result
1221
- )
1222
- ).to eq(nil)
1230
+ specification.stream("Stream B").with_id(["8cee1139-4f96-483a-a175-2b947283c3c7"]).read_first.result,
1231
+ ),
1232
+ ).to be_nil
1223
1233
  expect(
1224
1234
  repository.read(
1225
- specification.stream("Stream B").with_id(["c31b327c-0da1-4178-a3cd-d2f6bb5d0688"]).read_first.result
1226
- )
1227
- ).to eq(nil)
1235
+ specification.stream("Stream B").with_id(["c31b327c-0da1-4178-a3cd-d2f6bb5d0688"]).read_first.result,
1236
+ ),
1237
+ ).to be_nil
1228
1238
  expect(repository.read(specification.with_id([]).result).to_a).to eq([])
1229
1239
  end
1230
1240
 
@@ -1295,7 +1305,7 @@ module RubyEventStore
1295
1305
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1296
1306
 
1297
1307
  expect(repository.read(specification.stream("whatever").older_than(Time.utc(2020, 1, 2)).result).to_a).to eq(
1298
- [event_1]
1308
+ [event_1],
1299
1309
  )
1300
1310
  end
1301
1311
 
@@ -1306,7 +1316,7 @@ module RubyEventStore
1306
1316
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1307
1317
 
1308
1318
  expect(
1309
- repository.read(specification.stream("whatever").older_than_or_equal(Time.utc(2020, 1, 2)).result).to_a
1319
+ repository.read(specification.stream("whatever").older_than_or_equal(Time.utc(2020, 1, 2)).result).to_a,
1310
1320
  ).to eq([event_1, event_2])
1311
1321
  end
1312
1322
 
@@ -1317,7 +1327,7 @@ module RubyEventStore
1317
1327
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1318
1328
 
1319
1329
  expect(repository.read(specification.stream("whatever").newer_than(Time.utc(2020, 1, 2)).result).to_a).to eq(
1320
- [event_3]
1330
+ [event_3],
1321
1331
  )
1322
1332
  end
1323
1333
 
@@ -1328,7 +1338,7 @@ module RubyEventStore
1328
1338
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1329
1339
 
1330
1340
  expect(
1331
- repository.read(specification.stream("whatever").newer_than_or_equal(Time.utc(2020, 1, 2)).result).to_a
1341
+ repository.read(specification.stream("whatever").newer_than_or_equal(Time.utc(2020, 1, 2)).result).to_a,
1332
1342
  ).to eq([event_2, event_3])
1333
1343
  end
1334
1344
 
@@ -1348,7 +1358,7 @@ module RubyEventStore
1348
1358
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1349
1359
 
1350
1360
  expect(repository.read(specification.older_than_or_equal(Time.utc(2020, 1, 2)).result).to_a).to eq(
1351
- [event_1, event_2]
1361
+ [event_1, event_2],
1352
1362
  )
1353
1363
  end
1354
1364
 
@@ -1368,7 +1378,7 @@ module RubyEventStore
1368
1378
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1369
1379
 
1370
1380
  expect(repository.read(specification.newer_than_or_equal(Time.utc(2020, 1, 2)).result).to_a).to eq(
1371
- [event_2, event_3]
1381
+ [event_2, event_3],
1372
1382
  )
1373
1383
  end
1374
1384
 
@@ -1379,7 +1389,7 @@ module RubyEventStore
1379
1389
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1380
1390
 
1381
1391
  expect(
1382
- repository.read(specification.older_than(Time.utc(2020, 1, 2)).newer_than(Time.utc(2020, 1, 2)).result).to_a
1392
+ repository.read(specification.older_than(Time.utc(2020, 1, 2)).newer_than(Time.utc(2020, 1, 2)).result).to_a,
1383
1393
  ).to eq([])
1384
1394
  end
1385
1395
 
@@ -1390,7 +1400,7 @@ module RubyEventStore
1390
1400
  repository.append_to_stream([event_1, event_2, event_3], Stream.new("whatever"), version_any)
1391
1401
 
1392
1402
  expect(repository.read(specification.between(Time.utc(2020, 1, 1)...Time.utc(2020, 1, 3)).result).to_a).to eq(
1393
- [event_1, event_2]
1403
+ [event_1, event_2],
1394
1404
  )
1395
1405
  end
1396
1406
 
@@ -1400,17 +1410,21 @@ module RubyEventStore
1400
1410
  SRecord.new(
1401
1411
  event_id: e1 = SecureRandom.uuid,
1402
1412
  timestamp: Time.new(2020, 1, 1),
1403
- valid_at: Time.new(2020, 1, 9)
1413
+ valid_at: Time.new(2020, 1, 9),
1404
1414
  ),
1405
1415
  SRecord.new(
1406
1416
  event_id: e2 = SecureRandom.uuid,
1407
1417
  timestamp: Time.new(2020, 1, 3),
1408
- valid_at: Time.new(2020, 1, 6)
1418
+ valid_at: Time.new(2020, 1, 6),
1419
+ ),
1420
+ SRecord.new(
1421
+ event_id: e3 = SecureRandom.uuid,
1422
+ timestamp: Time.new(2020, 1, 2),
1423
+ valid_at: Time.new(2020, 1, 3),
1409
1424
  ),
1410
- SRecord.new(event_id: e3 = SecureRandom.uuid, timestamp: Time.new(2020, 1, 2), valid_at: Time.new(2020, 1, 3))
1411
1425
  ],
1412
1426
  Stream.new("Dummy"),
1413
- ExpectedVersion.any
1427
+ ExpectedVersion.any,
1414
1428
  )
1415
1429
  expect(repository.read(specification.result)).to eq_ids([e1, e2, e3])
1416
1430
  expect(repository.read(specification.as_at.result)).to eq_ids([e1, e3, e2])
@@ -1425,17 +1439,21 @@ module RubyEventStore
1425
1439
  SRecord.new(
1426
1440
  event_id: e1 = SecureRandom.uuid,
1427
1441
  timestamp: Time.new(2020, 1, 1),
1428
- valid_at: Time.new(2020, 1, 9)
1442
+ valid_at: Time.new(2020, 1, 9),
1429
1443
  ),
1430
1444
  SRecord.new(
1431
1445
  event_id: e2 = SecureRandom.uuid,
1432
1446
  timestamp: Time.new(2020, 1, 3),
1433
- valid_at: Time.new(2020, 1, 6)
1447
+ valid_at: Time.new(2020, 1, 6),
1448
+ ),
1449
+ SRecord.new(
1450
+ event_id: e3 = SecureRandom.uuid,
1451
+ timestamp: Time.new(2020, 1, 2),
1452
+ valid_at: Time.new(2020, 1, 3),
1434
1453
  ),
1435
- SRecord.new(event_id: e3 = SecureRandom.uuid, timestamp: Time.new(2020, 1, 2), valid_at: Time.new(2020, 1, 3))
1436
1454
  ],
1437
1455
  Stream.new("Dummy"),
1438
- ExpectedVersion.any
1456
+ ExpectedVersion.any,
1439
1457
  )
1440
1458
  expect(repository.read(specification.in_batches.result).to_a.flatten).to eq_ids([e1, e2, e3])
1441
1459
  expect(repository.read(specification.in_batches.as_at.result).to_a.flatten).to eq_ids([e1, e3, e2])
@@ -1448,7 +1466,7 @@ module RubyEventStore
1448
1466
  repository.append_to_stream(
1449
1467
  [],
1450
1468
  RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1451
- RubyEventStore::ExpectedVersion.any
1469
+ RubyEventStore::ExpectedVersion.any,
1452
1470
  )
1453
1471
  expect(repository.read(specification.result).count).to eq(0)
1454
1472
  end
@@ -1457,7 +1475,7 @@ module RubyEventStore
1457
1475
  repository.link_to_stream(
1458
1476
  [],
1459
1477
  RubyEventStore::Stream.new("whatever-non-globa"),
1460
- RubyEventStore::ExpectedVersion.any
1478
+ RubyEventStore::ExpectedVersion.any,
1461
1479
  )
1462
1480
  expect(repository.read(specification.result).count).to eq(0)
1463
1481
  end
@@ -1467,7 +1485,7 @@ module RubyEventStore
1467
1485
  repository.append_to_stream(
1468
1486
  events,
1469
1487
  RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1470
- RubyEventStore::ExpectedVersion.any
1488
+ RubyEventStore::ExpectedVersion.any,
1471
1489
  )
1472
1490
 
1473
1491
  batches = repository.read(specification.backward.limit(101).in_batches.result).to_a
@@ -1483,7 +1501,7 @@ module RubyEventStore
1483
1501
  repository.append_to_stream(
1484
1502
  events,
1485
1503
  RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1486
- RubyEventStore::ExpectedVersion.any
1504
+ RubyEventStore::ExpectedVersion.any,
1487
1505
  )
1488
1506
 
1489
1507
  batches = repository.read(specification.forward.limit(101).in_batches.result).to_a
@@ -1497,15 +1515,11 @@ module RubyEventStore
1497
1515
  specify "read in batches forward from named stream" do
1498
1516
  all_events = Array.new(400) { RubyEventStore::SRecord.new }
1499
1517
  all_events.each_slice(2) do |(first, second)|
1500
- repository.append_to_stream(
1501
- [first],
1502
- RubyEventStore::Stream.new("bazinga"),
1503
- RubyEventStore::ExpectedVersion.any
1504
- )
1518
+ repository.append_to_stream([first], RubyEventStore::Stream.new("bazinga"), RubyEventStore::ExpectedVersion.any)
1505
1519
  repository.append_to_stream(
1506
1520
  [second],
1507
1521
  RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1508
- RubyEventStore::ExpectedVersion.any
1522
+ RubyEventStore::ExpectedVersion.any,
1509
1523
  )
1510
1524
  end
1511
1525
  stream_events =
@@ -1524,10 +1538,13 @@ module RubyEventStore
1524
1538
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 29, 0))),
1525
1539
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 28, 0))),
1526
1540
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 27, 0))),
1527
- RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)), valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0))),
1541
+ RubyEventStore::SRecord.new(
1542
+ timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)),
1543
+ valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0)),
1544
+ ),
1528
1545
  ],
1529
1546
  RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
1530
- RubyEventStore::ExpectedVersion.any
1547
+ RubyEventStore::ExpectedVersion.any,
1531
1548
  )
1532
1549
 
1533
1550
  expect(repository.read(specification.result).to_a).to eq([records[0], records[1], records[2], records[3]])
@@ -1541,15 +1558,24 @@ module RubyEventStore
1541
1558
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 29, 0))),
1542
1559
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 28, 0))),
1543
1560
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 27, 0))),
1544
- RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)), valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0))),
1561
+ RubyEventStore::SRecord.new(
1562
+ timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)),
1563
+ valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0)),
1564
+ ),
1545
1565
  ],
1546
1566
  RubyEventStore::Stream.new("stream"),
1547
- RubyEventStore::ExpectedVersion.any
1567
+ RubyEventStore::ExpectedVersion.any,
1548
1568
  )
1549
1569
 
1550
- expect(repository.read(specification.stream("stream").result).to_a).to eq([records[0], records[1], records[2], records[3]])
1551
- expect(repository.read(specification.stream("stream").as_at.result).to_a).to eq([records[3], records[2], records[1], records[0]])
1552
- expect(repository.read(specification.stream("stream").as_of.result).to_a).to eq([records[2], records[1], records[0], records[3]])
1570
+ expect(repository.read(specification.stream("stream").result).to_a).to eq(
1571
+ [records[0], records[1], records[2], records[3]],
1572
+ )
1573
+ expect(repository.read(specification.stream("stream").as_at.result).to_a).to eq(
1574
+ [records[3], records[2], records[1], records[0]],
1575
+ )
1576
+ expect(repository.read(specification.stream("stream").as_of.result).to_a).to eq(
1577
+ [records[2], records[1], records[0], records[3]],
1578
+ )
1553
1579
  end
1554
1580
 
1555
1581
  specify "reading last event sorted by valid_at" do
@@ -1558,10 +1584,13 @@ module RubyEventStore
1558
1584
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 29, 0))),
1559
1585
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 28, 0))),
1560
1586
  RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 27, 0))),
1561
- RubyEventStore::SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)), valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0))),
1587
+ RubyEventStore::SRecord.new(
1588
+ timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)),
1589
+ valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0)),
1590
+ ),
1562
1591
  ],
1563
1592
  RubyEventStore::Stream.new("stream"),
1564
- RubyEventStore::ExpectedVersion.any
1593
+ RubyEventStore::ExpectedVersion.any,
1565
1594
  )
1566
1595
 
1567
1596
  expect(repository.read(specification.stream("stream").as_of.read_last.result)).to eq(records[3])
@@ -1573,10 +1602,13 @@ module RubyEventStore
1573
1602
  SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 29, 0))),
1574
1603
  SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 28, 0))),
1575
1604
  SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 27, 0))),
1576
- SRecord.new(timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)), valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0))),
1605
+ SRecord.new(
1606
+ timestamp: with_precision(Time.new(2023, 1, 1, 12, 26, 0)),
1607
+ valid_at: with_precision(Time.new(2023, 1, 1, 12, 30, 0)),
1608
+ ),
1577
1609
  ],
1578
1610
  Stream.new(GLOBAL_STREAM),
1579
- ExpectedVersion.any
1611
+ ExpectedVersion.any,
1580
1612
  )
1581
1613
 
1582
1614
  expect(repository.read(specification.as_of.read_last.result)).to eq(records[3])
@@ -1588,14 +1620,21 @@ module RubyEventStore
1588
1620
  SRecord.new(timestamp: with_precision(Time.utc(2023, 1, 1, 12, 29))),
1589
1621
  SRecord.new(timestamp: with_precision(Time.utc(2023, 1, 1, 12, 28))),
1590
1622
  SRecord.new(timestamp: with_precision(Time.utc(2023, 1, 1, 12, 27))),
1591
- SRecord.new(timestamp: with_precision(Time.utc(2023, 1, 1, 12, 26)), valid_at: with_precision(Time.utc(2023, 1, 1, 12, 30))),
1623
+ SRecord.new(
1624
+ timestamp: with_precision(Time.utc(2023, 1, 1, 12, 26)),
1625
+ valid_at: with_precision(Time.utc(2023, 1, 1, 12, 30)),
1626
+ ),
1592
1627
  ],
1593
1628
  Stream.new("stream"),
1594
- ExpectedVersion.any
1629
+ ExpectedVersion.any,
1595
1630
  )
1596
1631
 
1597
- expect(repository.read(specification.older_than(Time.utc(2023,1,1,12,28,1)).stream("stream").as_at.result).to_a).to eq([records[3], records[2], records[1]])
1598
- expect(repository.read(specification.older_than(Time.utc(2023,1,1,12,28,1)).stream("stream").as_of.result).to_a).to eq([records[2], records[1]])
1632
+ expect(
1633
+ repository.read(specification.older_than(Time.utc(2023, 1, 1, 12, 28, 1)).stream("stream").as_at.result).to_a,
1634
+ ).to eq([records[3], records[2], records[1]])
1635
+ expect(
1636
+ repository.read(specification.older_than(Time.utc(2023, 1, 1, 12, 28, 1)).stream("stream").as_of.result).to_a,
1637
+ ).to eq([records[2], records[1]])
1599
1638
  end
1600
1639
 
1601
1640
  private