diff --git a/rails_event_store/lib/rails_event_store/async_handler_helpers.rb b/rails_event_store/lib/rails_event_store/async_handler_helpers.rb index a0b1393b4d..b64d2cba71 100644 --- a/rails_event_store/lib/rails_event_store/async_handler_helpers.rb +++ b/rails_event_store/lib/rails_event_store/async_handler_helpers.rb @@ -7,14 +7,12 @@ def self.with_defaults end def self.with( - event_store: Rails.configuration.event_store, - event_store_locator: nil, - serializer: RubyEventStore::Serializers::YAML + serializer: RubyEventStore::Serializers::YAML, + event_store_locator: -> { Rails.configuration.event_store } ) Module.new do define_method :perform do |payload| - event_store = event_store_locator.call if event_store_locator - super(event_store.deserialize(serializer: serializer, **payload.transform_keys(&:to_sym))) + super(event_store_locator.call.deserialize(serializer: serializer, **payload.transform_keys(&:to_sym))) end end end diff --git a/rails_event_store/spec/async_handler_helpers_spec.rb b/rails_event_store/spec/async_handler_helpers_spec.rb index 8f1229c246..c3b70f259d 100644 --- a/rails_event_store/spec/async_handler_helpers_spec.rb +++ b/rails_event_store/spec/async_handler_helpers_spec.rb @@ -95,7 +95,7 @@ def perform(event) end specify "with specified event store" do - HandlerWithAnotherEventStore.prepend RailsEventStore::AsyncHandler.with(event_store: another_event_store) + HandlerWithAnotherEventStore.prepend RailsEventStore::AsyncHandler.with(event_store_locator: -> { another_event_store} ) event_store.subscribe_to_all_events(HandlerWithAnotherEventStore) event_store.publish(ev = RubyEventStore::Event.new) expect($queue.pop).to eq(ev) @@ -103,7 +103,6 @@ def perform(event) specify "with specified event store locator" do HandlerWithEventStoreLocator.prepend RailsEventStore::AsyncHandler.with( - event_store: nil, event_store_locator: -> { another_event_store } ) another_event_store.subscribe_to_all_events(HandlerWithEventStoreLocator) @@ -113,7 +112,7 @@ def perform(event) specify "with specified serializer" do HandlerWithSpecifiedSerializer.prepend RailsEventStore::AsyncHandler.with( - event_store: json_event_store, + event_store_locator: -> { json_event_store }, serializer: JSON ) json_event_store.subscribe_to_all_events(HandlerWithSpecifiedSerializer)