ruby_event_store-rom 0.30.0 → 0.31.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,206 @@
1
+ require 'ruby_event_store/rom/event_repository'
2
+ require 'ruby_event_store/spec/event_repository_lint'
3
+
4
+ module RubyEventStore::ROM
5
+ RSpec.shared_examples :rom_event_repository do |repository_class|
6
+ subject(:repository) { repository_class.new(rom: env) }
7
+
8
+ let(:env) { rom_helper.env }
9
+ let(:container) { env.container }
10
+ let(:rom_db) { container.gateways[:default] }
11
+
12
+ around(:each) do |example|
13
+ rom_helper.run_lifecycle { example.run }
14
+ end
15
+
16
+ let(:test_race_conditions_auto) { rom_helper.has_connection_pooling? }
17
+ let(:test_race_conditions_any) { rom_helper.has_connection_pooling? }
18
+ let(:test_expected_version_auto) { true }
19
+ let(:test_link_events_to_stream) { true }
20
+ let(:test_binary) { false }
21
+
22
+ let(:default_stream) { RubyEventStore::Stream.new('stream') }
23
+ let(:global_stream) { RubyEventStore::Stream.new('all') }
24
+ let(:mapper) { RubyEventStore::Mappers::NullMapper.new }
25
+
26
+ it_behaves_like :event_repository, repository_class
27
+
28
+ specify "#initialize requires ROM::Env" do
29
+ expect{repository_class.new(rom: nil)}.to raise_error do |err|
30
+ expect(err).to be_a(ArgumentError)
31
+ expect(err.message).to eq("Must specify rom")
32
+ end
33
+ end
34
+
35
+ specify "#initialize uses ROM.env by default" do
36
+ expect{repository_class.new}.to raise_error(ArgumentError)
37
+ RubyEventStore::ROM.env = env
38
+ expect{repository_class.new}.not_to raise_error
39
+ RubyEventStore::ROM.env = nil
40
+ end
41
+
42
+ specify "#has_event? to raise exception for bad ID" do
43
+ expect(repository.has_event?('0')).to eq(false)
44
+ end
45
+
46
+ specify "all considered internal detail" do
47
+ repository.append_to_stream(
48
+ [SRecord.new],
49
+ RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
50
+ RubyEventStore::ExpectedVersion.any
51
+ )
52
+ reserved_stream = RubyEventStore::Stream.new("all")
53
+
54
+ expect{ repository.read(RubyEventStore::Specification.new(repository, mapper).stream("all").result) }.to raise_error(RubyEventStore::ReservedInternalName)
55
+ expect{ repository.read(RubyEventStore::Specification.new(repository, mapper).stream("all").backward.result) }.to raise_error(RubyEventStore::ReservedInternalName)
56
+ expect{ repository.read(RubyEventStore::Specification.new(repository, mapper).stream("all").from(:head).limit(5).result) }.to raise_error(RubyEventStore::ReservedInternalName)
57
+ expect{ repository.read(RubyEventStore::Specification.new(repository, mapper).stream("all").from(:head).limit(5).backward.result) }.to raise_error(RubyEventStore::ReservedInternalName)
58
+ end
59
+
60
+ specify "explicit sorting by position rather than accidental" do
61
+ events = [
62
+ SRecord.new(
63
+ event_id: u1 = SecureRandom.uuid,
64
+ data: YAML.dump({}),
65
+ metadata: YAML.dump({}),
66
+ event_type: "TestDomainEvent"
67
+ ),
68
+ SRecord.new(
69
+ event_id: u2 = SecureRandom.uuid,
70
+ data: YAML.dump({}),
71
+ metadata: YAML.dump({}),
72
+ event_type: "TestDomainEvent"
73
+ ),
74
+ SRecord.new(
75
+ event_id: u3 = SecureRandom.uuid,
76
+ data: YAML.dump({}),
77
+ metadata: YAML.dump({}),
78
+ event_type: "TestDomainEvent"
79
+ )
80
+ ]
81
+
82
+ repo = Repositories::Events.new(container)
83
+ repo.create_changeset(events).commit
84
+
85
+ expect(repo.events.to_a.size).to eq(3)
86
+
87
+ repo.stream_entries.changeset(Repositories::StreamEntries::Create, [
88
+ {stream: default_stream.name, event_id: events[1].event_id, position: 1},
89
+ {stream: default_stream.name, event_id: events[0].event_id, position: 0},
90
+ {stream: default_stream.name, event_id: events[2].event_id, position: 2}
91
+ ]).commit
92
+
93
+ expect(repo.stream_entries.to_a.size).to eq(3)
94
+
95
+ # ActiveRecord::Schema.define do
96
+ # self.verbose = false
97
+ # remove_index :event_store_events_in_streams, [:stream, :position]
98
+ # end
99
+
100
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).stream("stream").from(:head).limit(3).result).map(&:event_id)).to eq([u1,u2,u3])
101
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).stream("stream").result).map(&:event_id)).to eq([u1,u2,u3])
102
+
103
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).stream("stream").backward.from(:head).limit(3).result).map(&:event_id)).to eq([u3,u2,u1])
104
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).stream("stream").backward.result).map(&:event_id)).to eq([u3,u2,u1])
105
+ end
106
+
107
+ specify "explicit sorting by id rather than accidental for all events" do
108
+ events = [
109
+ SRecord.new(
110
+ event_id: u1 = SecureRandom.uuid,
111
+ data: YAML.dump({}),
112
+ metadata: YAML.dump({}),
113
+ event_type: "TestDomainEvent"
114
+ ),
115
+ SRecord.new(
116
+ event_id: u2 = SecureRandom.uuid,
117
+ data: YAML.dump({}),
118
+ metadata: YAML.dump({}),
119
+ event_type: "TestDomainEvent"
120
+ ),
121
+ SRecord.new(
122
+ event_id: u3 = SecureRandom.uuid,
123
+ data: YAML.dump({}),
124
+ metadata: YAML.dump({}),
125
+ event_type: "TestDomainEvent"
126
+ )
127
+ ]
128
+
129
+ repo = Repositories::Events.new(container)
130
+ repo.create_changeset(events).commit
131
+
132
+ expect(repo.events.to_a.size).to eq(3)
133
+
134
+ repo.stream_entries.changeset(Repositories::StreamEntries::Create, [
135
+ {stream: global_stream.name, event_id: events[0].event_id, position: 1},
136
+ {stream: global_stream.name, event_id: events[1].event_id, position: 0},
137
+ {stream: global_stream.name, event_id: events[2].event_id, position: 2}
138
+ ]).commit
139
+
140
+ expect(repo.stream_entries.to_a.size).to eq(3)
141
+
142
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).from(:head).limit(3).result).map(&:event_id)).to eq([u1,u2,u3])
143
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).from(:head).limit(3).backward.result).map(&:event_id)).to eq([u3,u2,u1])
144
+ end
145
+
146
+ specify "nested transaction - events still not persisted if append failed" do
147
+ repository.append_to_stream([
148
+ event = SRecord.new(event_id: SecureRandom.uuid),
149
+ ], default_stream, RubyEventStore::ExpectedVersion.none)
150
+
151
+ env.unit_of_work do
152
+ expect do
153
+ repository.append_to_stream([
154
+ SRecord.new(
155
+ event_id: '9bedf448-e4d0-41a3-a8cd-f94aec7aa763'
156
+ ),
157
+ ], default_stream, RubyEventStore::ExpectedVersion.none)
158
+ end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
159
+ expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey
160
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).from(:head).limit(2).result).to_a).to eq([event])
161
+ end
162
+ expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey
163
+ expect(repository.read(RubyEventStore::Specification.new(repository, mapper).from(:head).limit(2).result).to_a).to eq([event])
164
+ end
165
+
166
+ def cleanup_concurrency_test
167
+ rom_helper.close_pool_connection
168
+ end
169
+
170
+ def verify_conncurency_assumptions
171
+ expect(rom_helper.connection_pool_size).to eq(5)
172
+ end
173
+
174
+ # TODO: Port from AR to ROM
175
+ def additional_limited_concurrency_for_auto_check
176
+ positions = container.relations[:stream_entries].
177
+ ordered(:forward, default_stream).
178
+ map { |entity| entity[:position] }
179
+ expect(positions).to eq((0..positions.size-1).to_a)
180
+ end
181
+
182
+ private
183
+
184
+ # TODO: Port from AR to ROM
185
+ def count_queries(&block)
186
+ count = 0
187
+ counter_f = ->(_name, _started, _finished, _unique_id, payload) {
188
+ unless %w[ CACHE SCHEMA ].include?(payload[:name])
189
+ count += 1
190
+ end
191
+ }
192
+ # ActiveSupport::Notifications.subscribed(counter_f, "sql.active_record", &block)
193
+ count
194
+ end
195
+
196
+ # TODO: Port from AR to ROM
197
+ def expect_query(match, &block)
198
+ count = 0
199
+ counter_f = ->(_name, _started, _finished, _unique_id, payload) {
200
+ count += 1 if match === payload[:sql]
201
+ }
202
+ # ActiveSupport::Notifications.subscribed(counter_f, "sql.active_record", &block)
203
+ expect(count).to eq(1)
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,75 @@
1
+ RSpec.shared_examples :events_relation do |relation_class|
2
+ subject(:relation) { container.relations[:events] }
3
+
4
+ let(:env) { rom_helper.env }
5
+ let(:container) { env.container }
6
+ let(:rom_db) { 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 '#exist? indicates if one instance of the record exists by primary key' do
17
+ event = {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now}
18
+
19
+ expect(relation.by_pk(event[:id]).exist?).to eq(false)
20
+
21
+ relation.insert(event)
22
+
23
+ expect(relation.by_pk(event[:id]).exist?).to eq(true)
24
+ end
25
+
26
+ specify '#insert verifies tuple is unique' do
27
+ events = [
28
+ {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now},
29
+ {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now},
30
+ {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now}
31
+ ]
32
+
33
+ relation.command(:create).call(events[0..1])
34
+
35
+ expect do
36
+ env.handle_error(:unique_violation) { relation.insert(events[0]) }
37
+ end.to raise_error(RubyEventStore::EventDuplicatedInStream)
38
+ expect do
39
+ env.handle_error(:unique_violation) { relation.insert(events[1]) }
40
+ end.to raise_error(RubyEventStore::EventDuplicatedInStream)
41
+ expect{relation.insert(events[2])}.not_to raise_error
42
+ expect do
43
+ env.handle_error(:unique_violation) { relation.insert(events[2]) }
44
+ end.to raise_error(RubyEventStore::EventDuplicatedInStream)
45
+ end
46
+
47
+ specify '#by_pk finds tuples by ID' do
48
+ events = [
49
+ {id: id = SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now},
50
+ {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now},
51
+ {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now}
52
+ ]
53
+
54
+ relation.command(:create).call(events)
55
+
56
+ expect(relation.by_pk(id).to_a.size).to eq(1)
57
+ expect(relation.by_pk(id).to_a.map { |e| e[:id] }).to eq([id])
58
+ end
59
+
60
+ specify 'each method returns proper type' do
61
+ events = [
62
+ {id: id = SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now},
63
+ {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now},
64
+ {id: SecureRandom.uuid, event_type: "TestEvent", data: "", metadata: "", created_at: Time.now}
65
+ ]
66
+
67
+ relation.command(:create).call(events)
68
+
69
+ expect(relation.by_pk(SecureRandom.uuid).exist?).to eq(false)
70
+ expect(relation.by_pk(id).exist?).to eq(true)
71
+
72
+ expect(relation.by_pk(id)).to be_a(relation.class)
73
+ # expect(relation.by_pk(id).first).to be_a(::ROM::Struct)
74
+ end
75
+ end
@@ -0,0 +1,198 @@
1
+ RSpec.shared_examples :stream_entries_relation do |relation_class|
2
+ subject(:relation) { container.relations[:stream_entries] }
3
+
4
+ let(:env) { rom_helper.env }
5
+ let(:container) { env.container }
6
+ let(:rom_db) { 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: 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: id1 = SecureRandom.uuid},
179
+ {stream: 'stream', position: 1, event_id: id2 = SecureRandom.uuid},
180
+ {stream: 'stream', position: 2, event_id: id3 = 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
@@ -0,0 +1,15 @@
1
+ module RubyEventStore::ROM
2
+ RSpec.shared_examples :rom_spec_helper do |rom_spec_helper_class|
3
+ let(:env) { rom_helper.env }
4
+ let(:container) { env.container }
5
+ let(:rom_db) { 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.container).to be_a(::ROM::Container)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
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(:container) { env.container }
7
+ let(:rom_db) { 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.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
@@ -29,17 +29,17 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'rake', '~> 10.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.6'
31
31
  spec.add_development_dependency 'sqlite3', '1.3.13'
32
- spec.add_development_dependency 'pg', '0.21'
33
- spec.add_development_dependency 'mysql2', '0.4.10'
34
- spec.add_development_dependency 'mutant-rspec', '~> 0.8.14'
32
+ spec.add_development_dependency 'pg', '>= 0.21'
33
+ spec.add_development_dependency 'mysql2', '>= 0.4.10'
34
+ spec.add_development_dependency 'mutant-rspec', '>= 0.8.14'
35
35
  spec.add_development_dependency 'fakefs', '~> 0.11.2'
36
36
  spec.add_development_dependency 'childprocess'
37
37
  spec.add_development_dependency 'google-protobuf', '~> 3.5.1.2'
38
38
 
39
- spec.add_dependency 'ruby_event_store', '= 0.30.0'
39
+ spec.add_dependency 'ruby_event_store', '= 0.31.0'
40
40
  spec.add_dependency 'sequel', '>= 4.49'
41
- spec.add_dependency 'rom-sql', '~> 2.4'
42
- spec.add_dependency 'rom-repository', '~> 2.0'
43
- spec.add_dependency 'rom-changeset', '~> 1.0'
44
41
  spec.add_dependency 'dry-types', '~> 0.12.2'
42
+ spec.add_dependency 'rom-sql', '>= 2.4'
43
+ spec.add_dependency 'rom-repository', '>= 2.0'
44
+ spec.add_dependency 'rom-changeset', '>= 1.0'
45
45
  end