Skip to content

Commit 55cf839

Browse files
mostlyobviousfidelmpraglowski
committed
Serializer is always dependent on DATA_TYPE
Co-authored-by: Szymon Fiedler <[email protected]> Co-authored-by: Mirosław Pragłowski <[email protected]>
1 parent 1f93e89 commit 55cf839

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

ruby_event_store-active_record/spec/event_repository_spec.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ module RubyEventStore
88
module ActiveRecord
99
::RSpec.describe EventRepository do
1010
helper = SpecHelper.new
11-
mk_repository = -> do
12-
serializer =
13-
case ENV["DATA_TYPE"]
14-
when /json/
15-
JSON
16-
else
17-
RubyEventStore::Serializers::YAML
18-
end
19-
EventRepository.new(serializer: serializer)
11+
12+
mk_serializer = -> do
13+
case ENV["DATA_TYPE"]
14+
when /json/
15+
JSON
16+
else
17+
RubyEventStore::Serializers::YAML
18+
end
2019
end
2120

21+
mk_repository = -> { EventRepository.new(serializer: mk_serializer.call) }
22+
2223
it_behaves_like "event repository", mk_repository, helper
2324

2425
let(:repository) { mk_repository.call }
@@ -74,7 +75,7 @@ module ActiveRecord
7475
end
7576

7677
specify "use default models" do
77-
repository = EventRepository.new(serializer: Serializers::YAML)
78+
repository = EventRepository.new(serializer: mk_serializer.call)
7879
expect(repository.instance_variable_get(:@event_klass)).to be(Event)
7980
expect(repository.instance_variable_get(:@stream_klass)).to be(EventInStream)
8081
end
@@ -83,7 +84,7 @@ module ActiveRecord
8384
repository =
8485
EventRepository.new(
8586
model_factory: WithAbstractBaseClass.new(CustomApplicationRecord),
86-
serializer: Serializers::YAML,
87+
serializer: mk_serializer.call,
8788
)
8889
expect(repository.instance_variable_get(:@event_klass).ancestors).to include(CustomApplicationRecord)
8990
expect(repository.instance_variable_get(:@stream_klass).ancestors).to include(CustomApplicationRecord)
@@ -93,7 +94,7 @@ module ActiveRecord
9394
repository =
9495
EventRepository.new(
9596
model_factory: WithAbstractBaseClass.new(CustomApplicationRecord),
96-
serializer: Serializers::YAML,
97+
serializer: mk_serializer.call,
9798
)
9899
repository.append_to_stream([event = SRecord.new], Stream.new(GLOBAL_STREAM), ExpectedVersion.any)
99100
reader = SpecificationReader.new(repository, Mappers::Default.new)

ruby_event_store-active_record/spec/with_abstract_base_class_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ module ActiveRecord
99
::RSpec.describe WithAbstractBaseClass do
1010
include SchemaHelper
1111

12+
mk_serializer = -> do
13+
case ENV["DATA_TYPE"]
14+
when /json/
15+
JSON
16+
else
17+
RubyEventStore::Serializers::YAML
18+
end
19+
end
20+
1221
specify "Base for event factory models must be an abstract class" do
1322
NonAbstractClass = Class.new(::ActiveRecord::Base)
1423
expect { WithAbstractBaseClass.new(NonAbstractClass) }.to raise_error(ArgumentError).with_message(
@@ -53,7 +62,7 @@ module ActiveRecord
5362
repository =
5463
EventRepository.new(
5564
model_factory: WithAbstractBaseClass.new(CustomApplicationRecord),
56-
serializer: Serializers::YAML,
65+
serializer: mk_serializer.call,
5766
)
5867
repository.append_to_stream([event = SRecord.new], Stream.new(GLOBAL_STREAM), ExpectedVersion.any)
5968
reader = SpecificationReader.new(repository, Mappers::Default.new)
@@ -73,7 +82,7 @@ module ActiveRecord
7382
repository =
7483
EventRepository.new(
7584
model_factory: WithAbstractBaseClass.new(CustomApplicationRecord),
76-
serializer: Serializers::YAML,
85+
serializer: mk_serializer.call,
7786
)
7887
repository.append_to_stream(
7988
[event = SRecord.new(event_type: "Dummy")],

0 commit comments

Comments
 (0)