Skip to content

Commit b9fa52d

Browse files
mpraglowskimostlyobvious
authored andcommitted
No more aggregate root configuration
Since we have introduced AggregateRoot::Repository it is easy to pass event store as a dependency there. No need to use AggregateRoot::Configuration and default_event_store. Make it explicte which event store is used. Less "magic".
1 parent 1446443 commit b9fa52d

File tree

5 files changed

+1
-59
lines changed

5 files changed

+1
-59
lines changed

aggregate_root/lib/aggregate_root.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require_relative "aggregate_root/version"
4-
require_relative "aggregate_root/configuration"
54
require_relative "aggregate_root/transform"
65
require_relative "aggregate_root/default_apply_strategy"
76
require_relative "aggregate_root/repository"

aggregate_root/lib/aggregate_root/configuration.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

aggregate_root/lib/aggregate_root/repository.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module AggregateRoot
44
class Repository
5-
def initialize(event_store = default_event_store)
5+
def initialize(event_store)
66
@event_store = event_store
77
end
88

@@ -29,9 +29,5 @@ def with_aggregate(aggregate, stream_name, &block)
2929
private
3030

3131
attr_reader :event_store
32-
33-
def default_event_store
34-
AggregateRoot.configuration.default_event_store
35-
end
3632
end
3733
end

aggregate_root/spec/repository_spec.rb

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,6 @@ def apply_order_expired(_event)
3939
end
4040
end
4141

42-
def with_default_event_store(store)
43-
previous = AggregateRoot.configuration.default_event_store
44-
AggregateRoot.configure { |config| config.default_event_store = store }
45-
yield
46-
AggregateRoot.configure { |config| config.default_event_store = previous }
47-
end
48-
49-
describe "#initialize" do
50-
it "should use default client if event_store not provided" do
51-
with_default_event_store(event_store) do
52-
repository = AggregateRoot::Repository.new
53-
54-
order = repository.load(order_klass.new(uuid), stream_name)
55-
order_created = Orders::Events::OrderCreated.new
56-
order.apply(order_created)
57-
repository.store(order, stream_name)
58-
59-
expect(event_store.read.stream(stream_name).to_a).to eq [order_created]
60-
end
61-
end
62-
63-
it "should prefer provided event_store client" do
64-
with_default_event_store(double(:event_store)) do
65-
repository = AggregateRoot::Repository.new(event_store)
66-
67-
order = repository.load(order_klass.new(uuid), stream_name)
68-
order_created = Orders::Events::OrderCreated.new
69-
order.apply(order_created)
70-
repository.store(order, stream_name)
71-
72-
expect(event_store.read.stream(stream_name).to_a).to eq [order_created]
73-
end
74-
end
75-
end
76-
7742
describe "#load" do
7843
specify do
7944
event_store.publish(Orders::Events::OrderCreated.new, stream_name: stream_name)

aggregate_root/spec/spec_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
require "ruby_event_store"
55
require_relative "../../support/helpers/rspec_defaults"
66

7-
RSpec.configure { |spec| spec.before(:each) { AggregateRoot.configure { |config| config.default_event_store = nil } } }
8-
97
module Orders
108
module Events
119
OrderCreated = Class.new(RubyEventStore::Event)

0 commit comments

Comments
 (0)