ruby_event_store-rom 0.35.0 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +84 -0
  4. data/Gemfile +4 -4
  5. data/Makefile +3 -0
  6. data/Rakefile +3 -3
  7. data/db/migrate/20180327044629_create_ruby_event_store_tables.rb +17 -8
  8. data/lib/ruby_event_store/rom.rb +19 -16
  9. data/lib/ruby_event_store/rom/adapters/memory/changesets/create_events.rb +17 -0
  10. data/lib/ruby_event_store/rom/adapters/memory/changesets/create_stream_entries.rb +17 -0
  11. data/lib/ruby_event_store/rom/adapters/memory/changesets/update_events.rb +16 -0
  12. data/lib/ruby_event_store/rom/adapters/memory/relations/events.rb +14 -5
  13. data/lib/ruby_event_store/rom/adapters/memory/relations/stream_entries.rb +8 -4
  14. data/lib/ruby_event_store/rom/adapters/memory/unit_of_work.rb +6 -21
  15. data/lib/ruby_event_store/rom/adapters/sql/changesets/create_events.rb +13 -0
  16. data/lib/ruby_event_store/rom/adapters/sql/changesets/update_events.rb +39 -0
  17. data/lib/ruby_event_store/rom/adapters/sql/index_violation_detector.rb +15 -16
  18. data/lib/ruby_event_store/rom/adapters/sql/relations/events.rb +13 -1
  19. data/lib/ruby_event_store/rom/adapters/sql/relations/stream_entries.rb +8 -4
  20. data/lib/ruby_event_store/rom/adapters/sql/tasks/migration_tasks.rake +16 -3
  21. data/lib/ruby_event_store/rom/changesets/create_events.rb +29 -0
  22. data/lib/ruby_event_store/rom/changesets/create_stream_entries.rb +21 -0
  23. data/lib/ruby_event_store/rom/changesets/update_events.rb +29 -0
  24. data/lib/ruby_event_store/rom/event_repository.rb +16 -6
  25. data/lib/ruby_event_store/rom/mappers/event_to_serialized_record.rb +1 -1
  26. data/lib/ruby_event_store/rom/mappers/stream_entry_to_serialized_record.rb +1 -1
  27. data/lib/ruby_event_store/rom/memory.rb +15 -3
  28. data/lib/ruby_event_store/rom/repositories/events.rb +18 -30
  29. data/lib/ruby_event_store/rom/repositories/stream_entries.rb +17 -18
  30. data/lib/ruby_event_store/rom/sql.rb +62 -12
  31. data/lib/ruby_event_store/rom/types.rb +13 -0
  32. data/lib/ruby_event_store/rom/unit_of_work.rb +1 -1
  33. data/lib/ruby_event_store/rom/version.rb +1 -1
  34. data/lib/ruby_event_store/spec/rom/event_repository_lint.rb +55 -90
  35. data/lib/ruby_event_store/spec/rom/relations/events_lint.rb +12 -12
  36. data/lib/ruby_event_store/spec/rom/relations/stream_entries_lint.rb +44 -44
  37. data/lib/ruby_event_store/spec/rom/spec_helper_lint.rb +1 -1
  38. data/lib/ruby_event_store/spec/rom/unit_of_work_lint.rb +1 -1
  39. data/ruby_event_store-rom.gemspec +12 -13
  40. metadata +40 -31
  41. data/lib/ruby_event_store/rom/adapters/sql/unit_of_work.rb +0 -37
@@ -1,35 +1,34 @@
1
1
  require_relative '../mappers/stream_entry_to_serialized_record'
2
+ require_relative '../changesets/create_stream_entries'
2
3
 
3
4
  module RubyEventStore
4
5
  module ROM
5
6
  module Repositories
6
7
  class StreamEntries < ::ROM::Repository[:stream_entries]
7
- class Create < ::ROM::Changeset::Create
8
- map do |tuple|
9
- Hash(created_at: Time.now).merge(tuple)
10
- end
11
- end
12
-
13
- POSITION_SHIFT = 1.freeze
8
+ POSITION_SHIFT = 1
14
9
 
15
10
  def create_changeset(event_ids, stream, resolved_version, global_stream: nil)
16
11
  tuples = []
17
12
 
18
13
  event_ids.each_with_index do |event_id, index|
19
- tuples << {
20
- stream: stream.name,
21
- position: resolved_version && resolved_version + index + POSITION_SHIFT,
22
- event_id: event_id
23
- } unless stream.global?
14
+ unless stream.global?
15
+ tuples << {
16
+ stream: stream.name,
17
+ position: resolved_version && resolved_version + index + POSITION_SHIFT,
18
+ event_id: event_id
19
+ }
20
+ end
21
+
22
+ next unless global_stream
24
23
 
25
- tuples << {
24
+ tuples << {
26
25
  stream: stream_entries.class::SERIALIZED_GLOBAL_STREAM_NAME,
27
26
  position: nil,
28
27
  event_id: event_id
29
- } if global_stream
28
+ }
30
29
  end
31
30
 
32
- stream_entries.changeset(Create, tuples)
31
+ stream_entries.create_changeset(tuples)
33
32
  end
34
33
 
35
34
  def delete(stream)
@@ -37,14 +36,14 @@ module RubyEventStore
37
36
  end
38
37
 
39
38
  def resolve_version(stream, expected_version)
40
- expected_version.resolve_for(stream, ->(_stream) {
39
+ expected_version.resolve_for(stream, lambda { |_stream|
41
40
  (stream_entries.max_position(stream) || {})[:position]
42
41
  })
43
42
  end
44
43
 
45
44
  def streams_of(event_id)
46
- stream_entries.by_event_id(event_id).map{|e| e[:stream]}
47
- .reject{|s| s == stream_entries.class::SERIALIZED_GLOBAL_STREAM_NAME}
45
+ stream_entries.by_event_id(event_id).map { |e| e[:stream] }
46
+ .reject { |s| s == stream_entries.class::SERIALIZED_GLOBAL_STREAM_NAME }
48
47
  end
49
48
  end
50
49
  end
@@ -1,9 +1,10 @@
1
1
  require 'ruby_event_store/rom'
2
2
  require 'rom/sql'
3
3
  require_relative 'adapters/sql/index_violation_detector'
4
- require_relative 'adapters/sql/unit_of_work'
5
4
  require_relative 'adapters/sql/relations/events'
6
5
  require_relative 'adapters/sql/relations/stream_entries'
6
+ require_relative 'adapters/sql/changesets/create_events'
7
+ require_relative 'adapters/sql/changesets/update_events'
7
8
 
8
9
  module RubyEventStore
9
10
  module ROM
@@ -17,33 +18,74 @@ module RubyEventStore
17
18
  def configure(env)
18
19
  # See: https://github.com/jeremyevans/sequel/blob/master/doc/transactions.rdoc
19
20
  env.register_unit_of_work_options(
20
- class: UnitOfWork,
21
- savepoint: true
21
+ savepoint: true,
22
+ # Committing changesets concurrently causes MySQL deadlocks
23
+ # which are not caught and retried by Sequel's built-in
24
+ # :retry_on option. This appears to be a result of how ROM
25
+ # handles exceptions which don't bubble up so that Sequel
26
+ # can retry transactions with the :retry_on option when there's
27
+ # a deadlock.
28
+ #
29
+ # This is exacerbated by the fact that changesets insert multiple
30
+ # tuples with individual INSERT statements because ROM specifies
31
+ # to Sequel to return a list of primary keys created. The likelihood
32
+ # of a deadlock is reduced with batched INSERT statements.
33
+ #
34
+ # For this reason we need to manually insert changeset records to avoid
35
+ # MySQL deadlocks or to allow Sequel to retry transactions
36
+ # when the :retry_on option is specified.
37
+ retry_on: Sequel::SerializationFailure,
38
+ before_retry: lambda { |_num, ex|
39
+ env.logger.warn("RETRY TRANSACTION [#{self.class.name} => #{ex.class.name}] #{ex.message}")
40
+ }
22
41
  )
23
42
 
24
- env.register_error_handler :unique_violation, -> ex {
43
+ env.register_error_handler :unique_violation, lambda { |ex|
25
44
  case ex
26
45
  when ::ROM::SQL::UniqueConstraintError, Sequel::UniqueConstraintViolation
27
46
  raise EventDuplicatedInStream if IndexViolationDetector.new.detect(ex.message)
47
+
28
48
  raise WrongExpectedEventVersion
29
49
  end
30
50
  }
31
51
 
32
- env.register_error_handler :not_found, -> (ex, event_id) {
52
+ env.register_error_handler :not_found, lambda { |ex, event_id|
33
53
  case ex
34
54
  when ::ROM::TupleCountMismatchError
35
- raise EventNotFound.new(event_id)
55
+ raise EventNotFound, event_id
36
56
  when Sequel::DatabaseError
37
57
  raise ex unless ex.message =~ /PG::InvalidTextRepresentation.*uuid/
38
- raise EventNotFound.new(event_id)
58
+
59
+ raise EventNotFound, event_id
39
60
  end
40
61
  }
41
62
  end
63
+
64
+ def supports_upsert?(db)
65
+ supports_on_duplicate_key_update?(db) ||
66
+ supports_insert_conflict_update?(db)
67
+ end
68
+
69
+ def supports_on_duplicate_key_update?(db)
70
+ db.adapter_scheme =~ /mysql/
71
+ end
72
+
73
+ def supports_insert_conflict_update?(db)
74
+ case db.adapter_scheme
75
+ when :postgres
76
+ true
77
+ when :sqlite
78
+ # Sqlite 3.24.0+ supports PostgreSQL upsert syntax
79
+ db.sqlite_version >= 32400
80
+ else
81
+ false
82
+ end
83
+ end
42
84
  end
43
85
 
44
86
  class SpecHelper
45
87
  attr_reader :env
46
-
88
+
47
89
  def initialize(database_uri = ENV['DATABASE_URL'])
48
90
  config = ::ROM::Configuration.new(
49
91
  :sql,
@@ -56,10 +98,10 @@ module RubyEventStore
56
98
  # config.default.use_logger Logger.new(STDOUT)
57
99
  # config.default.connection.pool.send(:preconnect, true)
58
100
  config.default.run_migrations
59
-
101
+
60
102
  @env = ROM.setup(config)
61
103
  end
62
-
104
+
63
105
  def run_lifecycle
64
106
  establish_gateway_connection
65
107
  load_gateway_schema
@@ -74,8 +116,12 @@ module RubyEventStore
74
116
  env.container.gateways.fetch(:default)
75
117
  end
76
118
 
119
+ def gateway_type?(name)
120
+ gateway.connection.database_type.eql?(name)
121
+ end
122
+
77
123
  def has_connection_pooling?
78
- !gateway.connection.database_type.eql?(:sqlite)
124
+ !gateway_type?(:sqlite)
79
125
  end
80
126
 
81
127
  def connection_pool_size
@@ -86,7 +132,11 @@ module RubyEventStore
86
132
  gateway.connection.pool.disconnect
87
133
  end
88
134
 
89
- protected
135
+ def supports_upsert?
136
+ SQL.supports_upsert?(gateway.connection)
137
+ end
138
+
139
+ protected
90
140
 
91
141
  def establish_gateway_connection
92
142
  # Manually preconnect because disconnecting and reconnecting
@@ -0,0 +1,13 @@
1
+ module RubyEventStore
2
+ module ROM
3
+ module Types
4
+ DateTime = ::ROM::Types::DateTime
5
+ .constructor { |value| value.is_a?(::String) ? ::DateTime.iso8601(value) : value }
6
+ .default { ::DateTime.now.new_offset(0) }
7
+
8
+ SerializedRecordSerializer = ::ROM::Types::String
9
+ # detects if the value is a Sequel::Postgres::JSONHash or Sequel::Postgres::JSONBHash
10
+ SerializedRecordDeserializer = ::ROM::Types::String.constructor { |v| v.class.name.upcase.include?('JSON') ? JSON.dump(v) : v }
11
+ end
12
+ end
13
+ end
@@ -8,7 +8,7 @@ module RubyEventStore
8
8
  end
9
9
 
10
10
  def call(**options)
11
- gateway = @env.container.gateways.fetch(options.delete(:gateway){:default})
11
+ gateway = @env.container.gateways.fetch(options.delete(:gateway) { :default })
12
12
 
13
13
  yield(changesets = [])
14
14
 
@@ -1,5 +1,5 @@
1
1
  module RubyEventStore
2
2
  module ROM
3
- VERSION = "0.35.0"
3
+ VERSION = "0.36.0"
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ module RubyEventStore::ROM
18
18
  let(:test_expected_version_auto) { true }
19
19
  let(:test_link_events_to_stream) { true }
20
20
  let(:test_binary) { false }
21
- let(:test_change) { false }
21
+ let(:test_change) { rom_helper.supports_upsert? }
22
22
 
23
23
  let(:default_stream) { RubyEventStore::Stream.new('stream') }
24
24
  let(:global_stream) { RubyEventStore::Stream.new('all') }
@@ -29,60 +29,44 @@ module RubyEventStore::ROM
29
29
 
30
30
  it_behaves_like :event_repository, repository_class
31
31
 
32
- specify "#initialize requires ROM::Env" do
33
- expect{repository_class.new(rom: nil)}.to raise_error do |err|
32
+ specify '#initialize requires ROM::Env' do
33
+ expect { repository_class.new(rom: nil) }.to raise_error do |err|
34
34
  expect(err).to be_a(ArgumentError)
35
- expect(err.message).to eq("Must specify rom")
35
+ expect(err.message).to eq('Must specify rom')
36
36
  end
37
37
  end
38
38
 
39
- specify "#initialize uses ROM.env by default" do
40
- expect{repository_class.new}.to raise_error(ArgumentError)
39
+ specify '#initialize uses ROM.env by default' do
40
+ expect { repository_class.new }.to raise_error(ArgumentError)
41
41
  RubyEventStore::ROM.env = env
42
- expect{repository_class.new}.not_to raise_error
42
+ expect { repository_class.new }.not_to raise_error
43
43
  RubyEventStore::ROM.env = nil
44
44
  end
45
45
 
46
- specify "#has_event? to raise exception for bad ID" do
46
+ specify '#has_event? to raise exception for bad ID' do
47
47
  expect(repository.has_event?('0')).to eq(false)
48
48
  end
49
49
 
50
- specify "all considered internal detail" do
50
+ specify 'all considered internal detail' do
51
51
  repository.append_to_stream(
52
52
  [RubyEventStore::SRecord.new],
53
53
  RubyEventStore::Stream.new(RubyEventStore::GLOBAL_STREAM),
54
54
  RubyEventStore::ExpectedVersion.any
55
55
  )
56
- reserved_stream = RubyEventStore::Stream.new("all")
57
56
 
58
- expect{ repository.read(specification.stream("all").result) }.to raise_error(RubyEventStore::ReservedInternalName)
59
- expect{ repository.read(specification.stream("all").backward.result) }.to raise_error(RubyEventStore::ReservedInternalName)
60
- expect{ repository.read(specification.stream("all").from(:head).limit(5).result) }.to raise_error(RubyEventStore::ReservedInternalName)
61
- expect{ repository.read(specification.stream("all").from(:head).limit(5).backward.result) }.to raise_error(RubyEventStore::ReservedInternalName)
57
+ expect { repository.read(specification.stream('all').result) }.to raise_error(RubyEventStore::ReservedInternalName)
58
+ expect { repository.read(specification.stream('all').backward.result) }.to raise_error(RubyEventStore::ReservedInternalName)
59
+ expect { repository.read(specification.stream('all').from(:head).limit(5).result) }.to raise_error(RubyEventStore::ReservedInternalName)
60
+ expect { repository.read(specification.stream('all').from(:head).limit(5).backward.result) }.to raise_error(RubyEventStore::ReservedInternalName)
62
61
 
63
- expect{ repository.count(specification.stream("all").result) }.to raise_error(RubyEventStore::ReservedInternalName)
62
+ expect { repository.count(specification.stream('all').result) }.to raise_error(RubyEventStore::ReservedInternalName)
64
63
  end
65
64
 
66
- specify "explicit sorting by position rather than accidental" do
65
+ specify 'explicit sorting by position rather than accidental' do
67
66
  events = [
68
- RubyEventStore::SRecord.new(
69
- event_id: u1 = SecureRandom.uuid,
70
- data: YAML.dump({}),
71
- metadata: YAML.dump({}),
72
- event_type: "TestDomainEvent"
73
- ),
74
- RubyEventStore::SRecord.new(
75
- event_id: u2 = SecureRandom.uuid,
76
- data: YAML.dump({}),
77
- metadata: YAML.dump({}),
78
- event_type: "TestDomainEvent"
79
- ),
80
- RubyEventStore::SRecord.new(
81
- event_id: u3 = SecureRandom.uuid,
82
- data: YAML.dump({}),
83
- metadata: YAML.dump({}),
84
- event_type: "TestDomainEvent"
85
- )
67
+ RubyEventStore::SRecord.new(event_id: u1 = SecureRandom.uuid),
68
+ RubyEventStore::SRecord.new(event_id: u2 = SecureRandom.uuid),
69
+ RubyEventStore::SRecord.new(event_id: u3 = SecureRandom.uuid)
86
70
  ]
87
71
 
88
72
  repo = Repositories::Events.new(container)
@@ -90,11 +74,11 @@ module RubyEventStore::ROM
90
74
 
91
75
  expect(repo.events.to_a.size).to eq(3)
92
76
 
93
- repo.stream_entries.changeset(Repositories::StreamEntries::Create, [
94
- {stream: default_stream.name, event_id: events[1].event_id, position: 1},
95
- {stream: default_stream.name, event_id: events[0].event_id, position: 0},
96
- {stream: default_stream.name, event_id: events[2].event_id, position: 2}
97
- ]).commit
77
+ repo.stream_entries.changeset(Changesets::CreateStreamEntries, [
78
+ { stream: default_stream.name, event_id: events[1].event_id, position: 1 },
79
+ { stream: default_stream.name, event_id: events[0].event_id, position: 0 },
80
+ { stream: default_stream.name, event_id: events[2].event_id, position: 2 }
81
+ ]).commit
98
82
 
99
83
  expect(repo.stream_entries.to_a.size).to eq(3)
100
84
 
@@ -103,33 +87,18 @@ module RubyEventStore::ROM
103
87
  # remove_index :event_store_events_in_streams, [:stream, :position]
104
88
  # end
105
89
 
106
- expect(repository.read(specification.stream("stream").from(:head).limit(3).result).map(&:event_id)).to eq([u1,u2,u3])
107
- expect(repository.read(specification.stream("stream").result).map(&:event_id)).to eq([u1,u2,u3])
90
+ expect(repository.read(specification.stream('stream').from(:head).limit(3).result).map(&:event_id)).to eq([u1, u2, u3])
91
+ expect(repository.read(specification.stream('stream').result).map(&:event_id)).to eq([u1, u2, u3])
108
92
 
109
- expect(repository.read(specification.stream("stream").backward.from(:head).limit(3).result).map(&:event_id)).to eq([u3,u2,u1])
110
- expect(repository.read(specification.stream("stream").backward.result).map(&:event_id)).to eq([u3,u2,u1])
93
+ expect(repository.read(specification.stream('stream').backward.from(:head).limit(3).result).map(&:event_id)).to eq([u3, u2, u1])
94
+ expect(repository.read(specification.stream('stream').backward.result).map(&:event_id)).to eq([u3, u2, u1])
111
95
  end
112
96
 
113
- specify "explicit sorting by id rather than accidental for all events" do
97
+ specify 'explicit sorting by id rather than accidental for all events' do
114
98
  events = [
115
- RubyEventStore::SRecord.new(
116
- event_id: u1 = SecureRandom.uuid,
117
- data: YAML.dump({}),
118
- metadata: YAML.dump({}),
119
- event_type: "TestDomainEvent"
120
- ),
121
- RubyEventStore::SRecord.new(
122
- event_id: u2 = SecureRandom.uuid,
123
- data: YAML.dump({}),
124
- metadata: YAML.dump({}),
125
- event_type: "TestDomainEvent"
126
- ),
127
- RubyEventStore::SRecord.new(
128
- event_id: u3 = SecureRandom.uuid,
129
- data: YAML.dump({}),
130
- metadata: YAML.dump({}),
131
- event_type: "TestDomainEvent"
132
- )
99
+ RubyEventStore::SRecord.new(event_id: u1 = SecureRandom.uuid),
100
+ RubyEventStore::SRecord.new(event_id: u2 = SecureRandom.uuid),
101
+ RubyEventStore::SRecord.new(event_id: u3 = SecureRandom.uuid)
133
102
  ]
134
103
 
135
104
  repo = Repositories::Events.new(container)
@@ -137,30 +106,28 @@ module RubyEventStore::ROM
137
106
 
138
107
  expect(repo.events.to_a.size).to eq(3)
139
108
 
140
- repo.stream_entries.changeset(Repositories::StreamEntries::Create, [
141
- {stream: global_stream.name, event_id: events[0].event_id, position: 1},
142
- {stream: global_stream.name, event_id: events[1].event_id, position: 0},
143
- {stream: global_stream.name, event_id: events[2].event_id, position: 2}
144
- ]).commit
109
+ repo.stream_entries.changeset(Changesets::CreateStreamEntries, [
110
+ { stream: global_stream.name, event_id: events[0].event_id, position: 1 },
111
+ { stream: global_stream.name, event_id: events[1].event_id, position: 0 },
112
+ { stream: global_stream.name, event_id: events[2].event_id, position: 2 }
113
+ ]).commit
145
114
 
146
115
  expect(repo.stream_entries.to_a.size).to eq(3)
147
116
 
148
- expect(repository.read(specification.from(:head).limit(3).result).map(&:event_id)).to eq([u1,u2,u3])
149
- expect(repository.read(specification.from(:head).limit(3).backward.result).map(&:event_id)).to eq([u3,u2,u1])
117
+ expect(repository.read(specification.from(:head).limit(3).result).map(&:event_id)).to eq([u1, u2, u3])
118
+ expect(repository.read(specification.from(:head).limit(3).backward.result).map(&:event_id)).to eq([u3, u2, u1])
150
119
  end
151
120
 
152
- specify "nested transaction - events still not persisted if append failed" do
121
+ specify 'nested transaction - events still not persisted if append failed' do
153
122
  repository.append_to_stream([
154
- event = RubyEventStore::SRecord.new(event_id: SecureRandom.uuid),
155
- ], default_stream, RubyEventStore::ExpectedVersion.none)
123
+ event = RubyEventStore::SRecord.new(event_id: SecureRandom.uuid)
124
+ ], default_stream, RubyEventStore::ExpectedVersion.none)
156
125
 
157
126
  env.unit_of_work do
158
127
  expect do
159
128
  repository.append_to_stream([
160
- RubyEventStore::SRecord.new(
161
- event_id: '9bedf448-e4d0-41a3-a8cd-f94aec7aa763'
162
- ),
163
- ], default_stream, RubyEventStore::ExpectedVersion.none)
129
+ RubyEventStore::SRecord.new(event_id: '9bedf448-e4d0-41a3-a8cd-f94aec7aa763')
130
+ ], default_stream, RubyEventStore::ExpectedVersion.none)
164
131
  end.to raise_error(RubyEventStore::WrongExpectedEventVersion)
165
132
  expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey
166
133
  expect(repository.read(specification.from(:head).limit(2).result).to_a).to eq([event])
@@ -179,32 +146,30 @@ module RubyEventStore::ROM
179
146
 
180
147
  # TODO: Port from AR to ROM
181
148
  def additional_limited_concurrency_for_auto_check
182
- positions = container.relations[:stream_entries].
183
- ordered(:forward, default_stream).
184
- map { |entity| entity[:position] }
185
- expect(positions).to eq((0..positions.size-1).to_a)
149
+ positions = container.relations[:stream_entries]
150
+ .ordered(:forward, default_stream)
151
+ .map { |entity| entity[:position] }
152
+ expect(positions).to eq((0..positions.size - 1).to_a)
186
153
  end
187
154
 
188
155
  private
189
156
 
190
157
  # TODO: Port from AR to ROM
191
- def count_queries(&block)
158
+ def count_queries
192
159
  count = 0
193
- counter_f = ->(_name, _started, _finished, _unique_id, payload) {
194
- unless %w[ CACHE SCHEMA ].include?(payload[:name])
195
- count += 1
196
- end
197
- }
160
+ # counter_f = lambda { |_name, _started, _finished, _unique_id, payload|
161
+ # count += 1 unless %w[CACHE SCHEMA].include?(payload[:name])
162
+ # }
198
163
  # ActiveSupport::Notifications.subscribed(counter_f, "sql.active_record", &block)
199
164
  count
200
165
  end
201
166
 
202
167
  # TODO: Port from AR to ROM
203
- def expect_query(match, &block)
168
+ def expect_query(_match)
204
169
  count = 0
205
- counter_f = ->(_name, _started, _finished, _unique_id, payload) {
206
- count += 1 if match === payload[:sql]
207
- }
170
+ # counter_f = lambda { |_name, _started, _finished, _unique_id, payload|
171
+ # count += 1 if match === payload[:sql]
172
+ # }
208
173
  # ActiveSupport::Notifications.subscribed(counter_f, "sql.active_record", &block)
209
174
  expect(count).to eq(1)
210
175
  end