eventus 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/eventus/aggregate_root.rb +7 -3
- data/lib/eventus/version.rb +1 -1
- data/spec/aggregate_root_spec.rb +6 -0
- metadata +1 -1
@@ -44,7 +44,13 @@ module Eventus
|
|
44
44
|
version = @stream.version
|
45
45
|
@stream.commit
|
46
46
|
true
|
47
|
-
rescue Eventus::ConcurrencyError
|
47
|
+
rescue Eventus::ConcurrencyError => e
|
48
|
+
on_concurrency_error(version, e)
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def on_concurrency_error(version, e)
|
48
54
|
committed = @stream.committed_events.drop(version)
|
49
55
|
uncommitted = @stream.uncommitted_events
|
50
56
|
conflict = committed.any?{ |e| uncommitted.any? {|u| self.class.conflict?(e['name'], u['name'])} }
|
@@ -52,8 +58,6 @@ module Eventus
|
|
52
58
|
false
|
53
59
|
end
|
54
60
|
|
55
|
-
protected
|
56
|
-
|
57
61
|
def apply_change(name, body=nil, is_new=true)
|
58
62
|
method_name = "apply_#{name}"
|
59
63
|
self.send method_name, body if self.respond_to?(method_name)
|
data/lib/eventus/version.rb
CHANGED
data/spec/aggregate_root_spec.rb
CHANGED
@@ -81,5 +81,11 @@ describe Eventus::AggregateRoot do
|
|
81
81
|
stream.should_receive(:uncommitted_events).and_return([{'name' => 'cake_baked'}])
|
82
82
|
lambda {aggregate.save}.should raise_error(Eventus::ConflictError)
|
83
83
|
end
|
84
|
+
|
85
|
+
it "should invoke on_concurrency_error when concurrency error" do
|
86
|
+
stream.should_receive(:commit).and_raise(Eventus::ConcurrencyError)
|
87
|
+
aggregate.should_receive(:on_concurrency_error).with(0, an_instance_of(Eventus::ConcurrencyError))
|
88
|
+
aggregate.save
|
89
|
+
end
|
84
90
|
end
|
85
91
|
end
|