Skip to content

Commit 1bb591f

Browse files
committed
Test bitemporal behavior
1. it should be possible to set valid_at 2. valid_at should be set to created_at if valid_at is null
1 parent 9ccdf0e commit 1bb591f

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

contrib/ruby_event_store-sequel/lib/ruby_event_store/sequel/event_repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def record(h)
168168
data: h[:data],
169169
metadata: h[:metadata],
170170
timestamp: h[:created_at].iso8601(TIMESTAMP_PRECISION),
171-
valid_at: h[:valid_at].iso8601(TIMESTAMP_PRECISION)
171+
valid_at: (h[:valid_at].nil? ? h[:created_at] : h[:valid_at]).iso8601(TIMESTAMP_PRECISION)
172172
)
173173
.deserialize(@serializer)
174174
end

contrib/ruby_event_store-sequel/spec/event_repository_spec.rb

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,56 @@ module Sequel
5959
expect do
6060
expect do
6161
repository.link_to_stream(
62-
%w[
63-
72922e65-1b32-4e97-8023-03ae81dd3a27
64-
d9f6d02a-05f0-4c27-86a9-ad7c4ef73042
65-
],
62+
%w[72922e65-1b32-4e97-8023-03ae81dd3a27 d9f6d02a-05f0-4c27-86a9-ad7c4ef73042],
6663
Stream.new("flow"),
6764
ExpectedVersion.none
6865
)
6966
end.to raise_error(EventNotFound)
7067
end.to match_query /SELECT .*event_store_events.*event_id.* FROM .*event_store_events.* WHERE .*event_store_events.*.event_id.* IN \('72922e65-1b32-4e97-8023-03ae81dd3a27', 'd9f6d02a-05f0-4c27-86a9-ad7c4ef73042'\).*/
7168
end
69+
70+
specify "with post-valid-at appended record" do
71+
helper.sequel[:event_store_events].insert(
72+
event_id: id = SecureRandom.uuid,
73+
data: "{}",
74+
metadata: "{}",
75+
event_type: "TestDomainEvent",
76+
created_at: t1 = with_precision(Time.now.utc),
77+
valid_at: t2 = with_precision(Time.at(0))
78+
)
79+
80+
helper.sequel[:event_store_events_in_streams].insert(
81+
stream: "stream",
82+
position: 1,
83+
event_id: id,
84+
created_at: t1
85+
)
86+
87+
record = repository.read(specification.result).first
88+
expect(record.timestamp).to eq(t1)
89+
expect(record.valid_at).to eq(t2)
90+
end
91+
92+
specify "with pre-valid-at appended record" do
93+
helper.sequel[:event_store_events].insert(
94+
event_id: id = SecureRandom.uuid,
95+
data: "{}",
96+
metadata: "{}",
97+
event_type: "TestDomainEvent",
98+
created_at: t = with_precision(Time.now.utc),
99+
valid_at: nil
100+
)
101+
102+
record = repository.read(specification.result).first
103+
expect(record.timestamp).to eq(t)
104+
expect(record.valid_at).to eq(t)
105+
end
106+
107+
private
108+
109+
def with_precision(time)
110+
time.round(TIMESTAMP_PRECISION)
111+
end
72112
end
73113
end
74114
end

0 commit comments

Comments
 (0)