eventus 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Eventus
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: