Skip to content

Commit 9132d71

Browse files
committed
Avoid name clash
1 parent 9574acc commit 9132d71

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ def append_to_stream_(records, stream, expected_version)
188188
end
189189

190190
def model_klasses
191-
@model_klasses ||= @model_factory.call.tap do |event_klass, stream_klass|
192-
if @serializer == NULL && json_data_type?(event_klass)
191+
@model_klasses ||= @model_factory.call.tap do |event_model, stream_model|
192+
if @serializer == NULL && json_data_type?(event_model)
193193
warn <<~MSG
194194
The data or metadata column is of a JSON/B type and expects a JSON string.
195195
@@ -210,7 +210,7 @@ def model_klasses
210210
RubyEventStore::ActiveRecord::EventRepository.new(serializer: JSON)
211211
MSG
212212
else
213-
event_klass.include(SkipJsonSerialization)
213+
event_model.include(SkipJsonSerialization)
214214
end
215215
end
216216
end

ruby_event_store-active_record/spec/event_repository_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,23 @@ module ActiveRecord
286286
specify "JSON/B backwards compatibility — explicit NULL serializer as advised before introduction of JSONClient" do
287287
skip unless %w[json jsonb].include?(ENV["DATA_TYPE"])
288288

289-
expect { repository = EventRepository.new(serializer: NULL) }.to output(<<~MSG).to_stderr
290-
The data or metadata column is of a JSON/B type and expects a JSON string.
289+
expect { EventRepository.new(serializer: NULL) }.not_to output.to_stderr
291290

292-
Yet the repository serializer is configured as RubyEventStore::NULL and it would not
293-
produce the expected JSON string.
291+
expect { repository = EventRepository.new(serializer: NULL).has_event?(SecureRandom.uuid) }.to output(<<~MSG).to_stderr
292+
The data or metadata column is of a JSON/B type and expects a JSON string.
294293
295-
In ActiveRecord there's an implicit serialization to JSON for JSON/B column types
296-
that made it work so far. This behaviour is unfortunately also a source of undesired
294+
Yet the repository serializer is configured as RubyEventStore::NULL and it would not
295+
produce the expected JSON string.
296+
297+
In ActiveRecord there's an implicit serialization to JSON for JSON/B column types
298+
that made it work so far. This behaviour is unfortunately also a source of undesired
297299
double serialization — first in the EventRepository, second in the ActiveRecord.
298-
299-
In the past we've advised workarounds that introduced configuration incosistency
300-
with other data types and serialization formats, i.e. explicitly passing NULL serializer
300+
301+
In the past we've advised workarounds that introduced configuration incosistency
302+
with other data types and serialization formats, i.e. explicitly passing NULL serializer
301303
just for the JSON/B data types.
302304
303-
As of now this special ActiveRecord behaviour is disabled. You should be using JSON
305+
As of now this special ActiveRecord behaviour is disabled. You should be using JSON
304306
serializer back again:
305307
306308
RubyEventStore::ActiveRecord::EventRepository.new(serializer: JSON)

0 commit comments

Comments
 (0)