Skip to content

Commit e58124c

Browse files
committed
Rescuing from doule JSON serialization must be explicitly enabled
Thus exposing the switch in client facade.
1 parent 402d876 commit e58124c

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def initialize(model_factory: WithDefaultModels.new, serializer:)
3232
@event_klass.include(SkipJsonSerialization)
3333
end
3434
@repo_reader = EventRepositoryReader.new(@event_klass, @stream_klass, serializer)
35-
rescue_from_double_json_serialization!
36-
3735
@index_violation_detector = IndexViolationDetector.new(@event_klass.table_name, @stream_klass.table_name)
3836
end
3937

ruby_event_store-active_record/spec/event_repository_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ module ActiveRecord
315315
skip unless %w[json jsonb].include?(ENV["DATA_TYPE"])
316316

317317
repository = EventRepository.new(serializer: JSON)
318+
repository.rescue_from_double_json_serialization!
318319
repository.append_to_stream(
319320
[SRecord.new(data: JSON.dump({ "simulate" => "double" }))],
320321
Stream.new("stream"),
@@ -338,6 +339,7 @@ module ActiveRecord
338339
skip unless %w[json jsonb].include?(ENV["DATA_TYPE"])
339340

340341
repository = EventRepository.new(serializer: JSON)
342+
repository.rescue_from_double_json_serialization!
341343
repository.append_to_stream([SRecord.new(data: "kaka dudu")], Stream.new("stream"), ExpectedVersion.any)
342344

343345
expect(repository.read(specification.backward.limit(1).result).first.data).to eq("kaka dudu")

ruby_event_store/lib/ruby_event_store/client.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def initialize(
4545
end
4646
end
4747

48+
def rescue_from_double_json_serialization!
49+
return unless @repository.respond_to? :rescue_from_double_json_serialization!
50+
@repository.rescue_from_double_json_serialization!
51+
end
52+
4853
# Persists events and notifies subscribed handlers about them
4954
#
5055
# @param events [Array<Event>, Event] event(s)

ruby_event_store/spec/client_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,5 +1007,17 @@ def event_id
10071007
expect(client.event_in_stream?(fact.event_id, GLOBAL_STREAM)).to be(true)
10081008
expect(client.event_in_stream?("924acfb8-755d-4fd5-b758-f92423b6560a", GLOBAL_STREAM)).to be(false)
10091009
end
1010+
1011+
specify "delegate double serialization rescue to supporting repository" do
1012+
client = Client.new(repository: repository = spy(:event_repository))
1013+
client.rescue_from_double_json_serialization!
1014+
1015+
expect(repository).to have_received(:rescue_from_double_json_serialization!)
1016+
end
1017+
1018+
specify "don't delegate double serialization rescue to not-supporting repository" do
1019+
client = Client.new(repository: repository = InMemoryRepository.new)
1020+
expect { client.rescue_from_double_json_serialization! }.not_to raise_error
1021+
end
10101022
end
10111023
end

0 commit comments

Comments
 (0)