ruby_event_store-rom 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/ruby_event_store/rom/changesets/create_events.rb +10 -18
- data/lib/ruby_event_store/rom/changesets/create_stream_entries.rb +6 -11
- data/lib/ruby_event_store/rom/changesets/update_events.rb +32 -19
- data/lib/ruby_event_store/rom/event_repository.rb +53 -51
- data/lib/ruby_event_store/rom/index_violation_detector.rb +29 -0
- data/lib/ruby_event_store/rom/mappers/event_to_serialized_record.rb +4 -4
- data/lib/ruby_event_store/rom/mappers/stream_entry_to_serialized_record.rb +5 -4
- data/lib/ruby_event_store/rom/rake_task.rb +5 -0
- data/lib/ruby_event_store/rom/relations/events.rb +81 -0
- data/lib/ruby_event_store/rom/relations/stream_entries.rb +90 -0
- data/lib/ruby_event_store/rom/repositories/events.rb +43 -29
- data/lib/ruby_event_store/rom/repositories/stream_entries.rb +7 -13
- data/lib/ruby_event_store/rom/{adapters/sql/tasks → tasks}/migration_tasks.rake +9 -9
- data/lib/ruby_event_store/rom/types.rb +2 -2
- data/lib/ruby_event_store/rom/unit_of_work.rb +29 -13
- data/lib/ruby_event_store/rom/version.rb +1 -1
- data/lib/ruby_event_store/rom.rb +29 -102
- data/lib/ruby_event_store-rom.rb +1 -1
- metadata +29 -48
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -84
- data/CHANGELOG.md +0 -9
- data/Gemfile +0 -12
- data/Makefile +0 -57
- data/Rakefile +0 -20
- data/db/migrate/20180327044629_create_ruby_event_store_tables.rb +0 -54
- data/db/migrate/20181026152045_index_by_event_type.rb +0 -9
- data/lib/ruby_event_store/rom/adapters/memory/changesets/create_events.rb +0 -19
- data/lib/ruby_event_store/rom/adapters/memory/changesets/create_stream_entries.rb +0 -19
- data/lib/ruby_event_store/rom/adapters/memory/changesets/update_events.rb +0 -18
- data/lib/ruby_event_store/rom/adapters/memory/relations/events.rb +0 -56
- data/lib/ruby_event_store/rom/adapters/memory/relations/stream_entries.rb +0 -114
- data/lib/ruby_event_store/rom/adapters/memory/unit_of_work.rb +0 -36
- data/lib/ruby_event_store/rom/adapters/sql/changesets/create_events.rb +0 -15
- data/lib/ruby_event_store/rom/adapters/sql/changesets/update_events.rb +0 -41
- data/lib/ruby_event_store/rom/adapters/sql/index_violation_detector.rb +0 -31
- data/lib/ruby_event_store/rom/adapters/sql/rake_task.rb +0 -5
- data/lib/ruby_event_store/rom/adapters/sql/relations/events.rb +0 -27
- data/lib/ruby_event_store/rom/adapters/sql/relations/stream_entries.rb +0 -72
- data/lib/ruby_event_store/rom/memory.rb +0 -82
- data/lib/ruby_event_store/rom/sql.rb +0 -169
- data/lib/ruby_event_store/rom/tuple_uniqueness_error.rb +0 -21
- data/lib/ruby_event_store/spec/rom/event_repository_lint.rb +0 -176
- data/lib/ruby_event_store/spec/rom/relations/events_lint.rb +0 -75
- data/lib/ruby_event_store/spec/rom/relations/stream_entries_lint.rb +0 -198
- data/lib/ruby_event_store/spec/rom/spec_helper_lint.rb +0 -15
- data/lib/ruby_event_store/spec/rom/unit_of_work_lint.rb +0 -37
- data/ruby_event_store-rom.gemspec +0 -37
@@ -1,198 +0,0 @@
|
|
1
|
-
RSpec.shared_examples :stream_entries_relation do |_relation_class|
|
2
|
-
subject(:relation) { rom_container.relations[:stream_entries] }
|
3
|
-
|
4
|
-
let(:env) { rom_helper.env }
|
5
|
-
let(:rom_container) { env.rom_container }
|
6
|
-
let(:rom_db) { rom_container.gateways[:default] }
|
7
|
-
|
8
|
-
around(:each) do |example|
|
9
|
-
rom_helper.run_lifecycle { example.run }
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'just created is empty' do
|
13
|
-
expect(relation.to_a).to be_empty
|
14
|
-
end
|
15
|
-
|
16
|
-
specify '#insert verifies tuple is unique steam and event_id' do
|
17
|
-
stream_entries = [
|
18
|
-
{ stream: 'stream', position: 0, event_id: id1 = SecureRandom.uuid },
|
19
|
-
{ stream: 'stream', position: 1, event_id: SecureRandom.uuid },
|
20
|
-
{ stream: 'stream', position: 2, event_id: SecureRandom.uuid }
|
21
|
-
]
|
22
|
-
|
23
|
-
relation.command(:create).call(stream_entries)
|
24
|
-
|
25
|
-
conflicting_event_id = { stream: 'stream', position: 3, event_id: id1, created_at: Time.now }
|
26
|
-
|
27
|
-
expect(relation.to_a.size).to eq(3)
|
28
|
-
expect do
|
29
|
-
env.handle_error(:unique_violation) { relation.insert(conflicting_event_id) }
|
30
|
-
end.to raise_error(RubyEventStore::EventDuplicatedInStream)
|
31
|
-
|
32
|
-
conflicting_position = { stream: 'stream', position: 2, event_id: SecureRandom.uuid, created_at: Time.now }
|
33
|
-
|
34
|
-
expect do
|
35
|
-
env.handle_error(:unique_violation) { relation.insert(conflicting_position) }
|
36
|
-
end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
|
37
|
-
end
|
38
|
-
|
39
|
-
specify '#take ignores nil' do
|
40
|
-
stream_entries = [
|
41
|
-
{ stream: 'stream', position: 0, event_id: id1 = SecureRandom.uuid },
|
42
|
-
{ stream: 'stream', position: 1, event_id: id2 = SecureRandom.uuid },
|
43
|
-
{ stream: 'stream', position: 2, event_id: id3 = SecureRandom.uuid }
|
44
|
-
]
|
45
|
-
|
46
|
-
relation.command(:create).call(stream_entries)
|
47
|
-
|
48
|
-
expect(relation.to_a.size).to eq(3)
|
49
|
-
expect(relation.take(nil).to_a.size).to eq(3)
|
50
|
-
expect(relation.take(nil).map { |e| e[:event_id] }).to eq([id1, id2, id3])
|
51
|
-
end
|
52
|
-
|
53
|
-
specify '#take returns specified number of tuples' do
|
54
|
-
stream_entries = [
|
55
|
-
{ stream: 'stream', position: 0, event_id: id1 = SecureRandom.uuid },
|
56
|
-
{ stream: 'stream', position: 1, event_id: id2 = SecureRandom.uuid },
|
57
|
-
{ stream: 'stream', position: 2, event_id: SecureRandom.uuid }
|
58
|
-
]
|
59
|
-
|
60
|
-
relation.command(:create).call(stream_entries)
|
61
|
-
|
62
|
-
expect(relation.to_a.size).to eq(3)
|
63
|
-
expect(relation.take(2).to_a.size).to eq(2)
|
64
|
-
expect(relation.take(2).map { |e| e[:event_id] }).to eq([id1, id2])
|
65
|
-
end
|
66
|
-
|
67
|
-
specify '#by_stream returns tuples for the specified stream' do
|
68
|
-
stream_entries = [
|
69
|
-
{ stream: 'stream', position: 0, event_id: SecureRandom.uuid },
|
70
|
-
{ stream: 'stream', position: 1, event_id: SecureRandom.uuid },
|
71
|
-
{ stream: 'stream2', position: 2, event_id: SecureRandom.uuid }
|
72
|
-
]
|
73
|
-
|
74
|
-
relation.command(:create).call(stream_entries)
|
75
|
-
|
76
|
-
expect(relation.to_a.size).to eq(3)
|
77
|
-
expect(relation.by_stream(RubyEventStore::Stream.new('stream')).to_a.size).to eq(2)
|
78
|
-
end
|
79
|
-
|
80
|
-
specify '#by_stream_and_event_id returns a tuple for the specified stream and event_id' do
|
81
|
-
stream = RubyEventStore::Stream.new('stream')
|
82
|
-
stream2 = RubyEventStore::Stream.new('stream2')
|
83
|
-
|
84
|
-
stream_entries = [
|
85
|
-
{ stream: stream.name, position: 0, event_id: id = SecureRandom.uuid },
|
86
|
-
{ stream: stream.name, position: 1, event_id: SecureRandom.uuid },
|
87
|
-
{ stream: stream2.name, position: 2, event_id: SecureRandom.uuid }
|
88
|
-
]
|
89
|
-
|
90
|
-
relation.command(:create).call(stream_entries)
|
91
|
-
|
92
|
-
expect(relation.to_a.size).to eq(3)
|
93
|
-
expect(relation.by_stream_and_event_id(stream, id)[:event_id]).to eq(id)
|
94
|
-
expect { relation.by_stream_and_event_id(stream2, id) }.to raise_error(ROM::TupleCountMismatchError)
|
95
|
-
end
|
96
|
-
|
97
|
-
specify '#max_position gets the largest position value' do
|
98
|
-
stream = RubyEventStore::Stream.new('stream')
|
99
|
-
stream2 = RubyEventStore::Stream.new('stream2')
|
100
|
-
stream3 = RubyEventStore::Stream.new('stream3')
|
101
|
-
|
102
|
-
stream_entries = [
|
103
|
-
{ stream: stream.name, position: 0, event_id: SecureRandom.uuid },
|
104
|
-
{ stream: stream.name, position: 2, event_id: SecureRandom.uuid },
|
105
|
-
{ stream: stream.name, position: 1, event_id: SecureRandom.uuid },
|
106
|
-
{ stream: stream2.name, position: 1, event_id: SecureRandom.uuid },
|
107
|
-
{ stream: stream2.name, position: 0, event_id: SecureRandom.uuid },
|
108
|
-
{ stream: stream2.name, position: 3, event_id: SecureRandom.uuid },
|
109
|
-
{ stream: stream2.name, position: 2, event_id: SecureRandom.uuid }
|
110
|
-
]
|
111
|
-
|
112
|
-
relation.command(:create).call(stream_entries)
|
113
|
-
|
114
|
-
expect(relation.to_a.size).to eq(7)
|
115
|
-
expect(relation.max_position(stream)).not_to be(nil)
|
116
|
-
expect(relation.max_position(stream)[:position]).to eq(2)
|
117
|
-
expect(relation.max_position(stream).to_h.keys).to eq([:position])
|
118
|
-
expect(relation.max_position(stream3)).to eq(nil)
|
119
|
-
end
|
120
|
-
|
121
|
-
specify '#ordered gets the stream entries :forward' do
|
122
|
-
stream = RubyEventStore::Stream.new('stream')
|
123
|
-
stream2 = RubyEventStore::Stream.new('stream2')
|
124
|
-
|
125
|
-
stream_entries = [
|
126
|
-
{ stream: stream.name, position: 0, event_id: SecureRandom.uuid },
|
127
|
-
{ stream: stream.name, position: 1, event_id: id1 = SecureRandom.uuid },
|
128
|
-
{ stream: stream.name, position: 2, event_id: id2 = SecureRandom.uuid },
|
129
|
-
{ stream: stream2.name, position: 0, event_id: SecureRandom.uuid },
|
130
|
-
{ stream: stream2.name, position: 1, event_id: SecureRandom.uuid },
|
131
|
-
{ stream: stream2.name, position: 2, event_id: SecureRandom.uuid },
|
132
|
-
{ stream: stream2.name, position: 3, event_id: SecureRandom.uuid }
|
133
|
-
]
|
134
|
-
|
135
|
-
relation.command(:create).call(stream_entries)
|
136
|
-
|
137
|
-
expect(relation.to_a.size).to eq(7)
|
138
|
-
expect(relation.ordered(:forward, stream).to_a.size).to eq(3)
|
139
|
-
expect(relation.ordered(:forward, stream).map { |e| e[:position] }).to eq([0, 1, 2])
|
140
|
-
|
141
|
-
offset1 = relation.by_stream_and_event_id(stream, id1)[:id]
|
142
|
-
offset2 = relation.by_stream_and_event_id(stream, id2)[:id]
|
143
|
-
|
144
|
-
expect(relation.ordered(:forward, stream, offset1).map { |e| e[:position] }).to eq([2])
|
145
|
-
expect(relation.ordered(:forward, stream, offset2).map { |e| e[:position] }).to eq([])
|
146
|
-
end
|
147
|
-
|
148
|
-
specify '#ordered gets the stream entries :backward' do
|
149
|
-
stream = RubyEventStore::Stream.new('stream')
|
150
|
-
stream2 = RubyEventStore::Stream.new('stream2')
|
151
|
-
|
152
|
-
stream_entries = [
|
153
|
-
{ stream: stream.name, position: 0, event_id: id1 = SecureRandom.uuid },
|
154
|
-
{ stream: stream.name, position: 1, event_id: id2 = SecureRandom.uuid },
|
155
|
-
{ stream: stream.name, position: 2, event_id: SecureRandom.uuid },
|
156
|
-
{ stream: stream2.name, position: 0, event_id: SecureRandom.uuid },
|
157
|
-
{ stream: stream2.name, position: 1, event_id: SecureRandom.uuid },
|
158
|
-
{ stream: stream2.name, position: 2, event_id: SecureRandom.uuid },
|
159
|
-
{ stream: stream2.name, position: 3, event_id: SecureRandom.uuid }
|
160
|
-
]
|
161
|
-
|
162
|
-
relation.command(:create).call(stream_entries)
|
163
|
-
|
164
|
-
expect(relation.to_a.size).to eq(7)
|
165
|
-
expect(relation.ordered(:backward, stream).to_a.size).to eq(3)
|
166
|
-
expect(relation.ordered(:backward, stream).map { |e| e[:position] }).to eq([2, 1, 0])
|
167
|
-
|
168
|
-
offset1 = relation.by_stream_and_event_id(stream, id1)[:id]
|
169
|
-
offset2 = relation.by_stream_and_event_id(stream, id2)[:id]
|
170
|
-
|
171
|
-
expect(relation.ordered(:backward, stream, offset1).map { |e| e[:position] }).to eq([])
|
172
|
-
expect(relation.ordered(:backward, stream, offset2).map { |e| e[:position] }).to eq([0])
|
173
|
-
end
|
174
|
-
|
175
|
-
specify 'each method returns proper type' do
|
176
|
-
stream = RubyEventStore::Stream.new('stream')
|
177
|
-
stream_entries = [
|
178
|
-
{ stream: 'stream', position: 0, event_id: SecureRandom.uuid },
|
179
|
-
{ stream: 'stream', position: 1, event_id: SecureRandom.uuid },
|
180
|
-
{ stream: 'stream', position: 2, event_id: SecureRandom.uuid }
|
181
|
-
]
|
182
|
-
|
183
|
-
relation.command(:create).call(stream_entries)
|
184
|
-
|
185
|
-
expect(relation.take(1)).to be_a(relation.class)
|
186
|
-
# expect(relation.take(1).one).to be_a(::ROM::Struct)
|
187
|
-
|
188
|
-
expect(relation.by_stream(stream)).to be_a(relation.class)
|
189
|
-
# expect(relation.by_stream(stream).take(1).one).to be_a(::ROM::Struct)
|
190
|
-
|
191
|
-
# expect(relation.by_stream_and_event_id(stream, id1)).to be_a(::ROM::Struct)
|
192
|
-
|
193
|
-
# expect(relation.max_position(stream)).to be_a(::ROM::Struct)
|
194
|
-
|
195
|
-
expect(relation.ordered(:forward, stream)).to be_a(relation.class)
|
196
|
-
# expect(relation.ordered(:forward, stream).take(1).one).to be_a(::ROM::Struct)
|
197
|
-
end
|
198
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module RubyEventStore::ROM
|
2
|
-
RSpec.shared_examples :rom_spec_helper do |_rom_spec_helper_class|
|
3
|
-
let(:env) { rom_helper.env }
|
4
|
-
let(:rom_container) { env.rom_container }
|
5
|
-
let(:rom_db) { rom_container.gateways[:default] }
|
6
|
-
|
7
|
-
around(:each) do |example|
|
8
|
-
rom_helper.run_lifecycle { example.run }
|
9
|
-
end
|
10
|
-
|
11
|
-
specify '#env gives access to ROM container' do
|
12
|
-
expect(subject.env.rom_container).to be_a(::ROM::Container)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module RubyEventStore::ROM
|
2
|
-
RSpec.shared_examples :unit_of_work do |unit_of_work_class|
|
3
|
-
subject(:unit_of_work) { unit_of_work_class.new(rom: env) }
|
4
|
-
|
5
|
-
let(:env) { rom_helper.env }
|
6
|
-
let(:v) { env.rom_container }
|
7
|
-
let(:rom_db) { rom_container.gateways[:default] }
|
8
|
-
|
9
|
-
around(:each) do |example|
|
10
|
-
rom_helper.run_lifecycle { example.run }
|
11
|
-
end
|
12
|
-
|
13
|
-
specify '#env gives access to ROM container' do
|
14
|
-
expect(subject.env.rom_container).to be_a(::ROM::Container)
|
15
|
-
end
|
16
|
-
|
17
|
-
specify '#call to throw an exeption' do
|
18
|
-
expect { subject.call(gateway: nil) {} }.to raise_error(KeyError)
|
19
|
-
end
|
20
|
-
|
21
|
-
specify '#env is the instance we specified' do
|
22
|
-
expect(subject.env).to eq(env)
|
23
|
-
end
|
24
|
-
|
25
|
-
specify '#env is the global instance' do
|
26
|
-
RubyEventStore::ROM.env = rom_helper.class.new.env
|
27
|
-
|
28
|
-
subject2 = unit_of_work_class.new
|
29
|
-
|
30
|
-
expect(subject2.env).to eq(RubyEventStore::ROM.env)
|
31
|
-
expect(subject2.env).not_to eq(subject.env)
|
32
|
-
expect(subject.env).not_to eq(RubyEventStore::ROM.env)
|
33
|
-
|
34
|
-
RubyEventStore::ROM.env = nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
lib = File.expand_path('lib', __dir__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'ruby_event_store/rom/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'ruby_event_store-rom'
|
7
|
-
spec.version = RubyEventStore::ROM::VERSION
|
8
|
-
spec.licenses = ['MIT']
|
9
|
-
spec.authors = ['Joel Van Horn']
|
10
|
-
spec.email = ['joel@joelvanhorn.com']
|
11
|
-
|
12
|
-
spec.summary = 'ROM events repository for Ruby Event Store'
|
13
|
-
spec.description = "Implementation of events repository based on ROM for Ruby Event Store'"
|
14
|
-
spec.homepage = 'https://railseventstore.org'
|
15
|
-
spec.metadata = {
|
16
|
-
'homepage_uri' => 'https://railseventstore.org/',
|
17
|
-
'changelog_uri' => 'https://github.com/RailsEventStore/rails_event_store/releases',
|
18
|
-
'source_code_uri' => 'https://github.com/RailsEventStore/rails_event_store',
|
19
|
-
'bug_tracker_uri' => 'https://github.com/RailsEventStore/rails_event_store/issues'
|
20
|
-
}
|
21
|
-
|
22
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
-
spec.bindir = 'exe'
|
24
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = ['lib']
|
26
|
-
|
27
|
-
spec.required_ruby_version = '>= 2.4'
|
28
|
-
|
29
|
-
spec.add_dependency 'dry-container', '>= 0.6'
|
30
|
-
spec.add_dependency 'dry-initializer', '>= 3.0'
|
31
|
-
spec.add_dependency 'dry-types', '>= 1.0'
|
32
|
-
spec.add_dependency 'rom-changeset', '>= 5.0'
|
33
|
-
spec.add_dependency 'rom-repository', '>= 5.0'
|
34
|
-
spec.add_dependency 'rom-sql', '>= 3.0'
|
35
|
-
spec.add_dependency 'ruby_event_store', '= 1.3.1'
|
36
|
-
spec.add_dependency 'sequel', '>= 5.11.0'
|
37
|
-
end
|