ruby_cqrs 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_cqrs.rb +0 -1
- data/lib/ruby_cqrs/contracts.rb +96 -0
- data/lib/ruby_cqrs/data/in_memory_event_store.rb +11 -14
- data/lib/ruby_cqrs/data/serialization.rb +2 -2
- data/lib/ruby_cqrs/domain/aggregate.rb +25 -2
- data/lib/ruby_cqrs/domain/aggregate_repository.rb +38 -17
- data/lib/ruby_cqrs/domain/event.rb +2 -1
- data/lib/ruby_cqrs/domain/snapshot.rb +1 -1
- data/lib/ruby_cqrs/version.rb +1 -1
- data/spec/{unit → lib/ruby_cqrs/data}/in_memory_event_store_spec.rb +1 -1
- data/spec/{unit → lib/ruby_cqrs/data}/serialization_spec.rb +2 -1
- data/spec/{unit → lib/ruby_cqrs/domain}/aggregate_repository_spec.rb +1 -37
- data/spec/{unit → lib/ruby_cqrs/domain}/aggregate_spec.rb +6 -7
- metadata +26 -12
- data/lib/ruby_cqrs/error.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55315f0c54dfcba27b2e0bd0a40390cb6743906a
|
4
|
+
data.tar.gz: 6d462d0ff742db26e70c0d5d51f89418b9906f82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bccb7a15ecf97f11c1e11d6bb03bf0d1ba3099c5dd3d215762f145751f5990ddbc3670641b45f8dc19c52c075ca6d645fd9c8594cb0d76731c6b8eaf0b3ba820
|
7
|
+
data.tar.gz: c052bdfd8e7a7ac56b6b7918dc74bf5f97d068937fcca70cddd0d4a18fd520f049d9bfc71227c95b224bf4cff4dc829c056eb38330024b3ba22ea03a6aa888f3
|
data/lib/ruby_cqrs.rb
CHANGED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
|
3
|
+
module RubyCqrs
|
4
|
+
module Validation
|
5
|
+
include Contracts
|
6
|
+
include Contracts::Modules
|
7
|
+
|
8
|
+
class EventStore
|
9
|
+
def self.valid? val
|
10
|
+
val.is_a? RubyCqrs::Data::EventStore
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Event
|
15
|
+
def self.valid? val
|
16
|
+
val.is_a? RubyCqrs::Domain::Event
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TypeOfEvent
|
21
|
+
def self.valid? val
|
22
|
+
val < RubyCqrs::Domain::Event
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Snapshot
|
27
|
+
def self.valid? val
|
28
|
+
val.is_a? RubyCqrs::Domain::Snapshot
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Aggregate
|
33
|
+
def self.valid? val
|
34
|
+
val.is_a? RubyCqrs::Domain::Aggregate
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class AggregateId
|
39
|
+
def self.valid? val
|
40
|
+
RubyCqrs::Guid.validate? val
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
AggregateChanges = ({ :events => ArrayOf[Event],
|
45
|
+
:aggregate_id => AggregateId,
|
46
|
+
:aggregate_type => String,
|
47
|
+
:expecting_source_version => Or[0, Pos],
|
48
|
+
:expecting_version => Pos })
|
49
|
+
|
50
|
+
AggregateChangesWithSnapshot = ({\
|
51
|
+
:events => ArrayOf[Event],
|
52
|
+
:aggregate_id => AggregateId,
|
53
|
+
:aggregate_type => String,
|
54
|
+
:expecting_source_version => Or[0, Pos],
|
55
|
+
:expecting_version => Pos,
|
56
|
+
:snapshot => {\
|
57
|
+
:state => Snapshot,
|
58
|
+
:state_type => String,
|
59
|
+
:version => Pos }})
|
60
|
+
|
61
|
+
AggregateState = ({\
|
62
|
+
:aggregate_id => AggregateId,
|
63
|
+
:aggregate_type => String,
|
64
|
+
:events => ArrayOf[Event]})
|
65
|
+
|
66
|
+
AggregateStateWithSnapshot = ({\
|
67
|
+
:aggregate_id => AggregateId,
|
68
|
+
:aggregate_type => String,
|
69
|
+
:snapshot => {\
|
70
|
+
:state => Snapshot,
|
71
|
+
:version => Pos },
|
72
|
+
:events => ArrayOf[Event]})
|
73
|
+
|
74
|
+
SerializedAggregateState = ({\
|
75
|
+
:aggregate_id => AggregateId,
|
76
|
+
:aggregate_type => String,
|
77
|
+
:events => ArrayOf[{\
|
78
|
+
:aggregate_id => AggregateId,
|
79
|
+
:event_type => String,
|
80
|
+
:version => Pos,
|
81
|
+
:data => String }]})
|
82
|
+
|
83
|
+
SerializedAggregateStateWithSnapshot = ({\
|
84
|
+
:aggregate_id => AggregateId,
|
85
|
+
:aggregate_type => String,
|
86
|
+
:snapshot => {\
|
87
|
+
:state_type => String,
|
88
|
+
:version => Pos,
|
89
|
+
:data => String },
|
90
|
+
:events => ArrayOf[{\
|
91
|
+
:aggregate_id => AggregateId,
|
92
|
+
:event_type => String,
|
93
|
+
:version => Pos,
|
94
|
+
:data => String }]})
|
95
|
+
end
|
96
|
+
end
|
@@ -1,26 +1,23 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require_relative '../contracts'
|
3
|
+
|
1
4
|
module RubyCqrs
|
2
5
|
module Data
|
3
6
|
class InMemoryEventStore
|
4
7
|
include EventStore
|
8
|
+
include Contracts
|
9
|
+
include Contracts::Modules
|
5
10
|
|
11
|
+
Contract None => Any
|
6
12
|
def initialize
|
7
13
|
@aggregate_store = {}
|
8
14
|
@event_store = {}
|
9
15
|
@snapshot_store = {}
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# :events => [ {:aggregate_id => the aggregate_id of the event belongs to(uuid),
|
16
|
-
# :event_type => the full qualified name of the event type(string),
|
17
|
-
# :version => the version number of the event(integer),
|
18
|
-
# :data => protobuf encoded content of the event object(string)}, ..., {} ],
|
19
|
-
# :snapshot => { :state_type => the full qualified name of the snapshot type(string),
|
20
|
-
# :version => the version number of the aggregate when snapshot(integer),
|
21
|
-
# :data => protobuf encoded content of the snapshot object(string)} }
|
22
|
-
# the snapshot object could be null; and the events array should return events which has a version
|
23
|
-
# number greater than the version number of the returning snapshot, if any.
|
18
|
+
Contract Validation::AggregateId, Any\
|
19
|
+
=> Or[Validation::SerializedAggregateState,\
|
20
|
+
Validation::SerializedAggregateStateWithSnapshot]
|
24
21
|
def load_by guid, command_context
|
25
22
|
key = guid.to_sym
|
26
23
|
state = { :aggregate_id => guid,
|
@@ -35,8 +32,8 @@ module RubyCqrs
|
|
35
32
|
state
|
36
33
|
end
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
Contract Or[ArrayOf[Validation::SerializedAggregateState],\
|
36
|
+
ArrayOf[Validation::SerializedAggregateStateWithSnapshot]], Any => nil
|
40
37
|
def save changes, command_context
|
41
38
|
changes.each do |change|
|
42
39
|
key = change[:aggregate_id].to_sym
|
@@ -2,8 +2,8 @@ require 'active_support/inflector'
|
|
2
2
|
require 'beefcake'
|
3
3
|
|
4
4
|
module RubyCqrs
|
5
|
-
class ObjectNotEncodableError <
|
6
|
-
class ObjectNotDecodableError <
|
5
|
+
class ObjectNotEncodableError < StandardError; end
|
6
|
+
class ObjectNotDecodableError < StandardError; end
|
7
7
|
|
8
8
|
module Data
|
9
9
|
module Encodable
|
@@ -1,10 +1,16 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
|
+
require 'contracts'
|
3
|
+
require_relative '../contracts'
|
2
4
|
|
3
5
|
module RubyCqrs
|
4
6
|
module Domain
|
5
7
|
module Aggregate
|
8
|
+
include Contracts
|
9
|
+
include Contracts::Modules
|
10
|
+
|
6
11
|
attr_reader :aggregate_id, :version
|
7
12
|
|
13
|
+
Contract None => Any
|
8
14
|
def initialize
|
9
15
|
@aggregate_id = Guid.create
|
10
16
|
@version = 0
|
@@ -14,12 +20,13 @@ module RubyCqrs
|
|
14
20
|
super
|
15
21
|
end
|
16
22
|
|
23
|
+
Contract Pos => Bool
|
17
24
|
def is_version_conflicted? client_side_version
|
18
25
|
client_side_version != @source_version
|
19
26
|
end
|
20
27
|
|
21
28
|
private
|
22
|
-
|
29
|
+
Contract Or[Validation::AggregateState, Validation::AggregateStateWithSnapshot] => nil
|
23
30
|
def load_from state
|
24
31
|
sorted_events = state[:events].sort { |x, y| x.version <=> y.version }
|
25
32
|
@aggregate_id = state[:aggregate_id]
|
@@ -28,8 +35,10 @@ module RubyCqrs
|
|
28
35
|
apply(event)
|
29
36
|
@source_version += 1
|
30
37
|
end
|
38
|
+
nil
|
31
39
|
end
|
32
40
|
|
41
|
+
Contract Or[Validation::AggregateState, Validation::AggregateStateWithSnapshot] => nil
|
33
42
|
def try_apply_snapshot_in state
|
34
43
|
if state.has_key? :snapshot and self.is_a? Snapshotable
|
35
44
|
self.send :apply_snapshot, state[:snapshot][:state]
|
@@ -37,8 +46,10 @@ module RubyCqrs
|
|
37
46
|
@source_version = state[:snapshot][:version]
|
38
47
|
self.send(:reset_countdown, state[:events].size)
|
39
48
|
end
|
49
|
+
nil
|
40
50
|
end
|
41
51
|
|
52
|
+
Contract None => Or[nil, Validation::AggregateChanges, Validation::AggregateChangesWithSnapshot]
|
42
53
|
def get_changes
|
43
54
|
return nil unless @pending_events.size > 0
|
44
55
|
changes = {
|
@@ -53,6 +64,7 @@ module RubyCqrs
|
|
53
64
|
changes
|
54
65
|
end
|
55
66
|
|
67
|
+
Contract Validation::AggregateChanges => nil
|
56
68
|
def try_extract_snapshot_into changes
|
57
69
|
snapshot_state = self.send :take_a_snapshot\
|
58
70
|
if self.is_a? Snapshotable and self.send(:should_take_a_snapshot?)
|
@@ -63,39 +75,50 @@ module RubyCqrs
|
|
63
75
|
:version => @version }
|
64
76
|
self.send :set_snapshot_taken
|
65
77
|
end
|
78
|
+
nil
|
66
79
|
end
|
67
80
|
|
81
|
+
Contract None => nil
|
68
82
|
def commit
|
69
83
|
@pending_events = []
|
70
84
|
@source_version = @version
|
71
85
|
if self.is_a? Snapshotable and self.send :should_reset_snapshot_countdown?
|
72
86
|
self.send(:reset_countdown, 0)
|
73
87
|
end
|
88
|
+
nil
|
74
89
|
end
|
75
90
|
|
91
|
+
Contract Validation::Event => nil
|
76
92
|
def raise_event(event)
|
77
|
-
raise NotADomainEventError unless event.is_a? Event
|
78
93
|
apply(event)
|
79
94
|
update_dispatch_detail_for(event)
|
80
95
|
@pending_events << event
|
96
|
+
nil
|
81
97
|
end
|
82
98
|
|
99
|
+
Contract Validation::Event => nil
|
83
100
|
def update_dispatch_detail_for(event)
|
84
101
|
event.instance_variable_set(:@aggregate_id, @aggregate_id)
|
85
102
|
event.instance_variable_set(:@version, @version)
|
103
|
+
nil
|
86
104
|
end
|
87
105
|
|
106
|
+
Contract Validation::Event => nil
|
88
107
|
def apply(event)
|
89
108
|
dispatch_handler_for(event)
|
90
109
|
self.send(:snapshot_countdown) if self.is_a? Snapshotable
|
91
110
|
@version += 1
|
111
|
+
nil
|
92
112
|
end
|
93
113
|
|
114
|
+
Contract Validation::Event => nil
|
94
115
|
def dispatch_handler_for(event)
|
95
116
|
target = retrieve_handler_for(event.class)
|
96
117
|
self.send(target, event)
|
118
|
+
nil
|
97
119
|
end
|
98
120
|
|
121
|
+
Contract Validation::TypeOfEvent => Symbol
|
99
122
|
def retrieve_handler_for(event_type)
|
100
123
|
@event_handler_cache[event_type] ||= begin
|
101
124
|
stripped_event_type_name = event_type.to_s.demodulize.underscore
|
@@ -1,19 +1,28 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
2
|
require_relative '../guid'
|
3
|
+
require 'contracts'
|
4
|
+
require_relative '../contracts'
|
3
5
|
|
4
6
|
module RubyCqrs
|
5
|
-
class AggregateNotFoundError <
|
6
|
-
class AggregateConcurrencyError <
|
7
|
-
class AggregateDuplicationError <
|
7
|
+
class AggregateNotFoundError < StandardError; end
|
8
|
+
class AggregateConcurrencyError < StandardError; end
|
9
|
+
class AggregateDuplicationError < StandardError; end
|
8
10
|
|
9
11
|
module Domain
|
10
12
|
class AggregateRepository
|
13
|
+
include Contracts
|
14
|
+
include Contracts::Modules
|
11
15
|
include RubyCqrs::Data::Decodable
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
raise ArgumentError unless
|
17
|
+
Contract Validation::EventStore, Any => Any
|
18
|
+
def initialize event_store, command_context
|
19
|
+
raise ArgumentError unless event_store.is_a? Data::EventStore
|
20
|
+
@event_store = event_store
|
21
|
+
@command_context = command_context
|
22
|
+
end
|
16
23
|
|
24
|
+
Contract Validation::AggregateId => Validation::Aggregate
|
25
|
+
def find_by aggregate_id
|
17
26
|
state = @event_store.load_by(aggregate_id, @command_context)
|
18
27
|
raise AggregateNotFoundError if (state.nil? or state[:aggregate_type].nil? or\
|
19
28
|
((state[:events].nil? or state[:events].empty?) and state[:snapshot].nil?))
|
@@ -21,21 +30,19 @@ module RubyCqrs
|
|
21
30
|
create_instance_from state
|
22
31
|
end
|
23
32
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
raise ArgumentError unless one_or_many_aggregate.is_a? Enumerable and one_or_many_aggregate.size > 0
|
29
|
-
delegate_persistence_of one_or_many_aggregate
|
33
|
+
Contract Validation::Aggregate => nil
|
34
|
+
def save one_aggregate
|
35
|
+
delegate_persistence_of [ one_aggregate ]
|
30
36
|
end
|
31
37
|
|
32
|
-
|
33
|
-
def
|
34
|
-
|
35
|
-
@event_store = event_store
|
36
|
-
@command_context = command_context
|
38
|
+
Contract ArrayOf[Validation::Aggregate] => nil
|
39
|
+
def save many_aggregate
|
40
|
+
delegate_persistence_of many_aggregate
|
37
41
|
end
|
38
42
|
|
43
|
+
private
|
44
|
+
Contract Or[Validation::SerializedAggregateState,\
|
45
|
+
Validation::SerializedAggregateStateWithSnapshot] => Validation::Aggregate
|
39
46
|
def create_instance_from state
|
40
47
|
try_decode_serialized_from state
|
41
48
|
instance = state[:aggregate_type].constantize.new
|
@@ -43,6 +50,7 @@ module RubyCqrs
|
|
43
50
|
instance
|
44
51
|
end
|
45
52
|
|
53
|
+
Contract ArrayOf[Validation::Aggregate] => nil
|
46
54
|
def delegate_persistence_of aggregates
|
47
55
|
verify_uniqueness_of aggregates
|
48
56
|
|
@@ -57,11 +65,16 @@ module RubyCqrs
|
|
57
65
|
nil
|
58
66
|
end
|
59
67
|
|
68
|
+
Contract ArrayOf[Validation::Aggregate] => nil
|
60
69
|
def verify_uniqueness_of aggregates
|
61
70
|
uniq_array = aggregates.uniq { |aggregate| aggregate.aggregate_id }
|
62
71
|
raise AggregateDuplicationError unless uniq_array.size == aggregates.size
|
72
|
+
nil
|
63
73
|
end
|
64
74
|
|
75
|
+
Contract ArrayOf[Validation::Aggregate] =>\
|
76
|
+
Or[ ArrayOf[Validation::SerializedAggregateState],\
|
77
|
+
ArrayOf[Validation::SerializedAggregateStateWithSnapshot]]
|
65
78
|
def prep_changes_for aggregates
|
66
79
|
to_return = []
|
67
80
|
aggregates.inject(to_return) do |product, aggregate|
|
@@ -74,12 +87,16 @@ module RubyCqrs
|
|
74
87
|
to_return
|
75
88
|
end
|
76
89
|
|
90
|
+
Contract Or[Validation::SerializedAggregateState,\
|
91
|
+
Validation::SerializedAggregateStateWithSnapshot] => nil
|
77
92
|
def try_decode_serialized_from state
|
78
93
|
state[:snapshot] = decode_snapshot_state_from state[:snapshot]\
|
79
94
|
if state.has_key? :snapshot
|
80
95
|
|
81
96
|
state[:events] = state[:events].map { |event_record| decode_event_from event_record }\
|
82
97
|
if state[:events].size > 0
|
98
|
+
|
99
|
+
nil
|
83
100
|
end
|
84
101
|
|
85
102
|
def decode_snapshot_state_from snapshot_record
|
@@ -94,6 +111,8 @@ module RubyCqrs
|
|
94
111
|
decoded_event
|
95
112
|
end
|
96
113
|
|
114
|
+
Contract Or[Validation::AggregateChanges,\
|
115
|
+
Validation::AggregateChangesWithSnapshot] => nil
|
97
116
|
def try_encode_serializable_in change
|
98
117
|
if change.has_key? :snapshot
|
99
118
|
encoded_snapshot = encode_data_from change[:snapshot][:state]
|
@@ -110,6 +129,8 @@ module RubyCqrs
|
|
110
129
|
:version => event.version }
|
111
130
|
}
|
112
131
|
end
|
132
|
+
|
133
|
+
nil
|
113
134
|
end
|
114
135
|
|
115
136
|
def encode_data_from obj
|
data/lib/ruby_cqrs/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative('
|
1
|
+
require_relative('../../../spec_helper')
|
2
2
|
|
3
3
|
describe RubyCqrs::Domain::AggregateRepository do
|
4
4
|
let(:unsorted_event_records) { [
|
@@ -23,29 +23,7 @@ describe RubyCqrs::Domain::AggregateRepository do
|
|
23
23
|
let(:repository) { RubyCqrs::Domain::AggregateRepository.new event_store, command_context }
|
24
24
|
let(:aggregate_type) { SomeDomain::AggregateRoot }
|
25
25
|
|
26
|
-
describe '#new' do
|
27
|
-
context 'when expecting arguments' do
|
28
|
-
it 'raises ArgumentError when the first argument is not an descendant from EventStore' do
|
29
|
-
expect { RubyCqrs::Domain::AggregateRepository.new Object.new, command_context }.to raise_error ArgumentError
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'is initialized with an EventStore instance and an CommandContext instance' do
|
33
|
-
RubyCqrs::Domain::AggregateRepository.new event_store, command_context
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
26
|
describe '#find_by' do
|
39
|
-
context 'when expecting arguments' do
|
40
|
-
it 'raises ArgumentError when aggregate_id is nil' do
|
41
|
-
expect { repository.find_by nil }.to raise_error ArgumentError
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'raises ArgumentError when aggregate_id is not a valid guid' do
|
45
|
-
expect { repository.find_by 'some_invalid_guid' }.to raise_error ArgumentError
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
27
|
it "delegates the actual data loading to the EventStore instance's #load_by" do
|
50
28
|
expect(event_store).to receive(:load_by) do |some_guid, some_command_context|
|
51
29
|
expect(some_guid).to be_a_valid_uuid
|
@@ -94,20 +72,6 @@ describe RubyCqrs::Domain::AggregateRepository do
|
|
94
72
|
end
|
95
73
|
|
96
74
|
describe '#save' do
|
97
|
-
context 'when expecting arguments' do
|
98
|
-
it 'raises ArgumentError when given 0 or nil argument or an 0 length enumerable' do
|
99
|
-
expect { repository.save }.to raise_error ArgumentError
|
100
|
-
expect { repository.save nil }.to raise_error ArgumentError
|
101
|
-
expect { repository.save [] }.to raise_error ArgumentError
|
102
|
-
end
|
103
|
-
it 'raises ArgumentError when the first argument is not an descendant from AggregateBase' do
|
104
|
-
expect { repository.save Object.new }.to raise_error ArgumentError
|
105
|
-
end
|
106
|
-
it 'raises ArgumentError when the first argument is not an enumerable of AggregateBase' do
|
107
|
-
expect { repository.save [ Object.new ] }.to raise_error ArgumentError
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
75
|
describe 'during the saving process' do
|
112
76
|
context 'when saving a single aggregate' do
|
113
77
|
context 'when the aggregate has not been changed' do
|
@@ -1,9 +1,14 @@
|
|
1
|
-
require_relative('
|
1
|
+
require_relative('../../../spec_helper')
|
2
2
|
|
3
3
|
describe RubyCqrs::Domain::Aggregate do
|
4
4
|
let(:aggregate_id) { SomeDomain::AGGREGATE_ID }
|
5
5
|
let(:aggregate) { SomeDomain::AggregateRoot.new }
|
6
|
+
let(:aggregate_type) { SomeDomain::AggregateRoot.name }
|
6
7
|
let(:unsorted_events) { [ SomeDomain::SecondEvent.new, SomeDomain::FirstEvent.new ] }
|
8
|
+
let(:state) {{
|
9
|
+
:aggregate_id => aggregate_id,
|
10
|
+
:aggregate_type => aggregate_type,
|
11
|
+
:events => unsorted_events }}
|
7
12
|
|
8
13
|
describe '#new' do
|
9
14
|
it 'has aggregate_id initilized as a valid uuid' do
|
@@ -20,10 +25,6 @@ describe RubyCqrs::Domain::Aggregate do
|
|
20
25
|
end
|
21
26
|
|
22
27
|
describe '#raise_event' do
|
23
|
-
it 'raise NotADomainEventError when raising an object that is not a proper event' do
|
24
|
-
expect { aggregate.fire_weird_stuff }.to raise_error(RubyCqrs::NotADomainEventError)
|
25
|
-
end
|
26
|
-
|
27
28
|
context 'after raising an event' do
|
28
29
|
it 'has version increased by 1' do
|
29
30
|
original_version = aggregate.version
|
@@ -47,7 +48,6 @@ describe RubyCqrs::Domain::Aggregate do
|
|
47
48
|
end
|
48
49
|
|
49
50
|
describe '#is_version_conflicted?' do
|
50
|
-
let(:state) { { :aggregate_id => aggregate_id, :events => unsorted_events } }
|
51
51
|
let(:loaded_aggregate) { aggregate.send(:load_from, state); aggregate; }
|
52
52
|
|
53
53
|
it 'returns true when supplied client side version does not match the server side persisted source_version' do
|
@@ -86,7 +86,6 @@ describe RubyCqrs::Domain::Aggregate do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
describe '#load_from' do
|
89
|
-
let(:state) { { :aggregate_id => aggregate_id, :events => unsorted_events } }
|
90
89
|
let(:loaded_aggregate) { aggregate.send(:load_from, state); aggregate; }
|
91
90
|
|
92
91
|
context 'when loading events' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_cqrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raven Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: contracts
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.0
|
55
69
|
description: a ruby implementation of cqrs, using event sourcing
|
56
70
|
email:
|
57
71
|
- ravenchen.cn@gmail.com
|
@@ -63,6 +77,7 @@ files:
|
|
63
77
|
- License.txt
|
64
78
|
- README.md
|
65
79
|
- lib/ruby_cqrs.rb
|
80
|
+
- lib/ruby_cqrs/contracts.rb
|
66
81
|
- lib/ruby_cqrs/data/event_store.rb
|
67
82
|
- lib/ruby_cqrs/data/in_memory_event_store.rb
|
68
83
|
- lib/ruby_cqrs/data/serialization.rb
|
@@ -71,18 +86,17 @@ files:
|
|
71
86
|
- lib/ruby_cqrs/domain/event.rb
|
72
87
|
- lib/ruby_cqrs/domain/snapshot.rb
|
73
88
|
- lib/ruby_cqrs/domain/snapshotable.rb
|
74
|
-
- lib/ruby_cqrs/error.rb
|
75
89
|
- lib/ruby_cqrs/guid.rb
|
76
90
|
- lib/ruby_cqrs/version.rb
|
77
91
|
- spec/feature/basic_usage_spec.rb
|
78
92
|
- spec/feature/snapshot_spec.rb
|
79
93
|
- spec/fixture/typical_domain.rb
|
94
|
+
- spec/lib/ruby_cqrs/data/in_memory_event_store_spec.rb
|
95
|
+
- spec/lib/ruby_cqrs/data/serialization_spec.rb
|
96
|
+
- spec/lib/ruby_cqrs/domain/aggregate_repository_spec.rb
|
97
|
+
- spec/lib/ruby_cqrs/domain/aggregate_spec.rb
|
80
98
|
- spec/spec_helper.rb
|
81
99
|
- spec/support/matchers.rb
|
82
|
-
- spec/unit/aggregate_repository_spec.rb
|
83
|
-
- spec/unit/aggregate_spec.rb
|
84
|
-
- spec/unit/in_memory_event_store_spec.rb
|
85
|
-
- spec/unit/serialization_spec.rb
|
86
100
|
homepage: https://github.com/iravench/ruby_cqrs
|
87
101
|
licenses:
|
88
102
|
- MIT
|
@@ -107,14 +121,14 @@ rubyforge_project:
|
|
107
121
|
rubygems_version: 2.4.6
|
108
122
|
signing_key:
|
109
123
|
specification_version: 4
|
110
|
-
summary: ruby_cqrs-0.2.
|
124
|
+
summary: ruby_cqrs-0.2.3
|
111
125
|
test_files:
|
112
126
|
- spec/feature/basic_usage_spec.rb
|
113
127
|
- spec/feature/snapshot_spec.rb
|
114
128
|
- spec/fixture/typical_domain.rb
|
129
|
+
- spec/lib/ruby_cqrs/data/in_memory_event_store_spec.rb
|
130
|
+
- spec/lib/ruby_cqrs/data/serialization_spec.rb
|
131
|
+
- spec/lib/ruby_cqrs/domain/aggregate_repository_spec.rb
|
132
|
+
- spec/lib/ruby_cqrs/domain/aggregate_spec.rb
|
115
133
|
- spec/spec_helper.rb
|
116
134
|
- spec/support/matchers.rb
|
117
|
-
- spec/unit/aggregate_repository_spec.rb
|
118
|
-
- spec/unit/aggregate_spec.rb
|
119
|
-
- spec/unit/in_memory_event_store_spec.rb
|
120
|
-
- spec/unit/serialization_spec.rb
|
data/lib/ruby_cqrs/error.rb
DELETED