sandthorn 1.0.0 → 1.1.0
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.
- checksums.yaml +5 -5
- data/Gemfile +1 -1
- data/README.md +5 -5
- data/lib/sandthorn.rb +0 -1
- data/lib/sandthorn/aggregate_root_base.rb +15 -27
- data/lib/sandthorn/aggregate_root_marshal.rb +4 -5
- data/lib/sandthorn/version.rb +1 -1
- data/sandthorn.gemspec +1 -1
- data/spec/aggregate_delta_spec.rb +6 -13
- data/spec/aggregate_events_spec.rb +3 -3
- data/spec/aggregate_root_spec.rb +37 -41
- data/spec/complex_aggregate_spec.rb +1 -1
- data/spec/constructor_events_spec.rb +5 -5
- data/spec/default_attributes_spec.rb +3 -3
- data/spec/initialize_signature_change_spec.rb +2 -2
- data/spec/stateless_events_spec.rb +11 -7
- data/spec/tracing_spec.rb +6 -6
- metadata +4 -13
- data/lib/sandthorn/event.rb +0 -61
- data/spec/aggregate_snapshot_spec.rb +0 -263
- data/spec/different_driver_spec.rb +0 -101
- data/spec/event_inspector_spec.rb +0 -152
- data/spec/event_spec.rb +0 -99
@@ -70,6 +70,6 @@ describe 'when using complex types in events' do
|
|
70
70
|
aggr = IAmComplex.aggregate_build @events
|
71
71
|
aggr.set_foo_bar_on_hello "morgan"
|
72
72
|
builded = IAmComplex.aggregate_build aggr.aggregate_events
|
73
|
-
expect(builded.hello.foo_bar).to
|
73
|
+
expect(builded.hello.foo_bar).to eq("morgan")
|
74
74
|
end
|
75
75
|
end
|
@@ -45,16 +45,16 @@ module Sandthorn
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should set instance variable in aggregate" do
|
48
|
-
expect(ConstructorEventsSpec.find(aggregate_id).name).to
|
48
|
+
expect(ConstructorEventsSpec.find(aggregate_id).name).to eq("create_name")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should have created an created_event" do
|
52
|
-
expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_name]).to
|
52
|
+
expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_name]).to eq("created_event")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should have set the attribute_delta name" do
|
56
|
-
expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_data]
|
57
|
-
expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_data][:
|
56
|
+
expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_data]).to have_key(:name)
|
57
|
+
expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_data][:name][:new_value]).to eq("create_name")
|
58
58
|
end
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
@@ -44,14 +44,14 @@ describe "when the initialize-method changes" do
|
|
44
44
|
it "should have an set the array attribute to [] on new" do
|
45
45
|
add_default_attributes
|
46
46
|
aggregate = DefaultAttributes.new
|
47
|
-
expect(aggregate.array).to
|
47
|
+
expect(aggregate.array).to eq([])
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should have set the array attribute to [] on rebuilt when attribute is intruduced after `new`" do
|
51
51
|
aggregate = DefaultAttributes.new
|
52
52
|
add_default_attributes
|
53
53
|
rebuilt_aggregate = DefaultAttributes.aggregate_build(aggregate.aggregate_events)
|
54
|
-
expect(rebuilt_aggregate.array).to
|
54
|
+
expect(rebuilt_aggregate.array).to eq([])
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should set the array attribute to ['banana'] on rebuilt" do
|
@@ -59,7 +59,7 @@ describe "when the initialize-method changes" do
|
|
59
59
|
aggregate = DefaultAttributes.new
|
60
60
|
aggregate.add_item 'banana'
|
61
61
|
rebuilt_aggregate = DefaultAttributes.aggregate_build(aggregate.aggregate_events)
|
62
|
-
expect(rebuilt_aggregate.array).to
|
62
|
+
expect(rebuilt_aggregate.array).to eq(['banana'])
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
@@ -18,8 +18,8 @@ describe "when the initialize-method changes" do
|
|
18
18
|
events = aggregate.aggregate_events
|
19
19
|
change_init
|
20
20
|
with_change = InitChange.new
|
21
|
-
expect(with_change.foo).to
|
21
|
+
expect(with_change.foo).to eq(:foo)
|
22
22
|
replayed = InitChange.aggregate_build(events)
|
23
|
-
expect(replayed.foo).to
|
23
|
+
expect(replayed.foo).to eq(:bar)
|
24
24
|
end
|
25
25
|
end
|
@@ -46,15 +46,19 @@ module Sandthorn
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should add one_event last on the aggregate" do
|
49
|
-
expect(last_event[:event_name]).to
|
49
|
+
expect(last_event[:event_name]).to eq("one_event")
|
50
50
|
end
|
51
51
|
|
52
|
-
it "should
|
53
|
-
expect(last_event[:
|
52
|
+
it "should add aggregate_id to events" do
|
53
|
+
expect(last_event[:aggregate_id]).to eq(subject.aggregate_id)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have stateless data in deltas in event" do
|
57
|
+
expect(last_event[:event_data]).to eq({:first => {:old_value => nil, :new_value => "first"}, :other => {:old_value => nil, :new_value => [1, 2, 3]}})
|
54
58
|
end
|
55
59
|
|
56
60
|
it "should have same name attribute after reload" do
|
57
|
-
expect(subject.name).to
|
61
|
+
expect(subject.name).to eq(reloaded_subject.name)
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
@@ -75,11 +79,11 @@ module Sandthorn
|
|
75
79
|
end
|
76
80
|
|
77
81
|
it "should have correct aggregate_id in event" do
|
78
|
-
expect(events.first[:aggregate_id]).to
|
82
|
+
expect(events.first[:aggregate_id]).to eq(aggregate_id)
|
79
83
|
end
|
80
84
|
|
81
85
|
it "should have event name one_event" do
|
82
|
-
expect(events.first[:event_name]).to
|
86
|
+
expect(events.first[:event_name]).to eq("one_event")
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
@@ -101,7 +105,7 @@ module Sandthorn
|
|
101
105
|
end
|
102
106
|
|
103
107
|
it "should override the name via the stateless event" do
|
104
|
-
expect(subject.name).not_to
|
108
|
+
expect(subject.name).not_to eq(reloaded_subject.name)
|
105
109
|
end
|
106
110
|
end
|
107
111
|
end
|
data/spec/tracing_spec.rb
CHANGED
@@ -40,7 +40,7 @@ describe "using a traced change" do
|
|
40
40
|
simple.aggregate_trace "123" do |traced|
|
41
41
|
traced.go
|
42
42
|
end
|
43
|
-
expect(simple.events_with_trace_info.last[:event_metadata]).to
|
43
|
+
expect(simple.events_with_trace_info.last[:event_metadata]).to eq("123")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
context "when not tracing" do
|
@@ -62,7 +62,7 @@ describe "using a traced change" do
|
|
62
62
|
s.charge_suspect_of_crime! "Theft"
|
63
63
|
end
|
64
64
|
event = suspect.events_with_trace_info.last
|
65
|
-
expect(event[:event_metadata]).to
|
65
|
+
expect(event[:event_metadata]).to eq("Ture Sventon")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should record optional other tracing information" do
|
@@ -71,7 +71,7 @@ describe "using a traced change" do
|
|
71
71
|
s.charge_suspect_of_crime! "Murder"
|
72
72
|
end
|
73
73
|
event = suspect.events_with_trace_info.last
|
74
|
-
expect(event[:event_metadata]).to
|
74
|
+
expect(event[:event_metadata]).to eq(trace_info)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
context "when initializing a new aggregate in a traced context" do
|
@@ -79,7 +79,7 @@ describe "using a traced change" do
|
|
79
79
|
UsualSuspect.aggregate_trace "Ture Sventon" do
|
80
80
|
suspect = UsualSuspect.new("Sonny").extend Sandthorn::EventInspector
|
81
81
|
event = suspect.events_with_trace_info.first
|
82
|
-
expect(event[:event_metadata]).to
|
82
|
+
expect(event[:event_metadata]).to eq("Ture Sventon")
|
83
83
|
end
|
84
84
|
end
|
85
85
|
it "should record tracing for all events in the trace block" do
|
@@ -88,7 +88,7 @@ describe "using a traced change" do
|
|
88
88
|
suspect = UsualSuspect.new("Sonny").extend Sandthorn::EventInspector
|
89
89
|
suspect.charge_suspect_of_crime! "Hit and run"
|
90
90
|
event = suspect.events_with_trace_info.last
|
91
|
-
expect(event[:event_metadata]).to
|
91
|
+
expect(event[:event_metadata]).to eq(trace_info)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
it "should record tracing for all events in the trace block" do
|
@@ -97,7 +97,7 @@ describe "using a traced change" do
|
|
97
97
|
suspect = UsualSuspect.new("Conny").extend Sandthorn::EventInspector
|
98
98
|
suspect.charge_suspect_of_crime! "Desception"
|
99
99
|
event = suspect.events_with_trace_info.last
|
100
|
-
expect(event[:event_metadata]).to
|
100
|
+
expect(event[:event_metadata]).to eq(trace_info)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandthorn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Krantz
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-05-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -194,7 +194,6 @@ files:
|
|
194
194
|
- lib/sandthorn/aggregate_root_snapshot.rb
|
195
195
|
- lib/sandthorn/bounded_context.rb
|
196
196
|
- lib/sandthorn/errors.rb
|
197
|
-
- lib/sandthorn/event.rb
|
198
197
|
- lib/sandthorn/event_inspector.rb
|
199
198
|
- lib/sandthorn/event_stores.rb
|
200
199
|
- lib/sandthorn/version.rb
|
@@ -202,23 +201,19 @@ files:
|
|
202
201
|
- spec/aggregate_delta_spec.rb
|
203
202
|
- spec/aggregate_events_spec.rb
|
204
203
|
- spec/aggregate_root_spec.rb
|
205
|
-
- spec/aggregate_snapshot_spec.rb
|
206
204
|
- spec/benchmark_spec.rb
|
207
205
|
- spec/bounded_context_spec.rb
|
208
206
|
- spec/complex_aggregate_spec.rb
|
209
207
|
- spec/constructor_events_spec.rb
|
210
208
|
- spec/db/sequel_driver.sqlite3_old
|
211
209
|
- spec/default_attributes_spec.rb
|
212
|
-
- spec/different_driver_spec.rb
|
213
|
-
- spec/event_inspector_spec.rb
|
214
|
-
- spec/event_spec.rb
|
215
210
|
- spec/event_stores_spec.rb
|
216
211
|
- spec/initialize_signature_change_spec.rb
|
217
212
|
- spec/spec_helper.rb
|
218
213
|
- spec/stateless_events_spec.rb
|
219
214
|
- spec/support/custom_matchers.rb
|
220
215
|
- spec/tracing_spec.rb
|
221
|
-
homepage:
|
216
|
+
homepage: https://github.com/Sandthorn/sandthorn
|
222
217
|
licenses:
|
223
218
|
- MIT
|
224
219
|
metadata: {}
|
@@ -238,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
238
233
|
version: '0'
|
239
234
|
requirements: []
|
240
235
|
rubyforge_project:
|
241
|
-
rubygems_version: 2.6
|
236
|
+
rubygems_version: 2.7.6
|
242
237
|
signing_key:
|
243
238
|
specification_version: 4
|
244
239
|
summary: Event sourcing gem
|
@@ -246,16 +241,12 @@ test_files:
|
|
246
241
|
- spec/aggregate_delta_spec.rb
|
247
242
|
- spec/aggregate_events_spec.rb
|
248
243
|
- spec/aggregate_root_spec.rb
|
249
|
-
- spec/aggregate_snapshot_spec.rb
|
250
244
|
- spec/benchmark_spec.rb
|
251
245
|
- spec/bounded_context_spec.rb
|
252
246
|
- spec/complex_aggregate_spec.rb
|
253
247
|
- spec/constructor_events_spec.rb
|
254
248
|
- spec/db/sequel_driver.sqlite3_old
|
255
249
|
- spec/default_attributes_spec.rb
|
256
|
-
- spec/different_driver_spec.rb
|
257
|
-
- spec/event_inspector_spec.rb
|
258
|
-
- spec/event_spec.rb
|
259
250
|
- spec/event_stores_spec.rb
|
260
251
|
- spec/initialize_signature_change_spec.rb
|
261
252
|
- spec/spec_helper.rb
|
data/lib/sandthorn/event.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'delegate'
|
2
|
-
|
3
|
-
module Sandthorn
|
4
|
-
class Event < SimpleDelegator
|
5
|
-
ATTRS = %i(
|
6
|
-
aggregate_id
|
7
|
-
aggregate_type
|
8
|
-
aggregate_version
|
9
|
-
timestamp
|
10
|
-
event_name
|
11
|
-
event_data
|
12
|
-
event_metadata
|
13
|
-
method_args
|
14
|
-
trace
|
15
|
-
)
|
16
|
-
|
17
|
-
ATTRS.each do |attr|
|
18
|
-
define_method(attr) do
|
19
|
-
self[attr]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def new_values
|
24
|
-
@changed_attributes ||= build_new_values
|
25
|
-
end
|
26
|
-
|
27
|
-
def attribute_deltas
|
28
|
-
@attribute_deltas ||= build_deltas
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def build_deltas
|
34
|
-
raw_deltas.map { |delta| AttributeDelta.new(delta) }
|
35
|
-
end
|
36
|
-
|
37
|
-
def build_new_values
|
38
|
-
attribute_deltas.each_with_object({}) do |delta, changed|
|
39
|
-
changed[delta.attribute_name.to_sym] = delta.new_value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def raw_deltas
|
44
|
-
fetch(:event_data, {}).fetch(:attribute_deltas, [])
|
45
|
-
end
|
46
|
-
|
47
|
-
class AttributeDelta < SimpleDelegator
|
48
|
-
ATTRS = %i(
|
49
|
-
attribute_name
|
50
|
-
old_value
|
51
|
-
new_value
|
52
|
-
)
|
53
|
-
|
54
|
-
ATTRS.each do |attr|
|
55
|
-
define_method(attr) do
|
56
|
-
self[attr]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,263 +0,0 @@
|
|
1
|
-
# require 'spec_helper'
|
2
|
-
# require 'sandthorn/aggregate_root_snapshot'
|
3
|
-
# require 'date'
|
4
|
-
|
5
|
-
|
6
|
-
# module BankAccountInterestCommands
|
7
|
-
# def calculate_interest! until_date = DateTime.now
|
8
|
-
# # skipping all safety-checks..
|
9
|
-
# # and this is of course horribly wrong financially speaking.. whatever
|
10
|
-
# pay_out_unpaid_interest!
|
11
|
-
# interest_calculation_time = until_date - @last_interest_calculation
|
12
|
-
# days_with_interest = interest_calculation_time.to_i
|
13
|
-
# unpaid_interest = @balance * @current_interest_info[:interest_rate] * days_with_interest / 365.2425
|
14
|
-
# added_unpaid_interest_event unpaid_interest,until_date
|
15
|
-
# end
|
16
|
-
|
17
|
-
# def pay_out_unpaid_interest!
|
18
|
-
# paid_out_unpaid_interest_balance_event @unpaid_interest_balance
|
19
|
-
# end
|
20
|
-
|
21
|
-
# def change_interest! new_interest_rate, interest_valid_from
|
22
|
-
# calculate_interest!
|
23
|
-
# changed_interest_rate_event new_interest_rate,interest_valid_from
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
# module BankAccountWithdrawalCommands
|
27
|
-
# def withdraw_from_atm! amount, atm_id
|
28
|
-
# withdrew_amount_from_atm_event amount, atm_id
|
29
|
-
# end
|
30
|
-
|
31
|
-
# def withdraw_from_cashier! amount, cashier_id
|
32
|
-
# withdrew_amount_from_cashier_event amount, cashier_id
|
33
|
-
# charged_cashier_withdrawal_fee_event 50
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
|
37
|
-
# module BankAccountVisaCardPurchasesCommands
|
38
|
-
# def charge_card! amount, merchant_id
|
39
|
-
# visa = VisaCardTransactionGateway.new
|
40
|
-
# transaction_id = visa.charge_card "3030-3333-4252-2535", merchant_id, amount
|
41
|
-
# paid_with_visa_card_event amount, transaction_id
|
42
|
-
# end
|
43
|
-
|
44
|
-
# end
|
45
|
-
|
46
|
-
# class VisaCardTransactionGateway
|
47
|
-
# def initialize
|
48
|
-
# @visa_connector = "foo_bar"
|
49
|
-
# end
|
50
|
-
# def charge_card visa_card_number, merchant_id, amount
|
51
|
-
# transaction_id = SecureRandom.uuid
|
52
|
-
# end
|
53
|
-
# end
|
54
|
-
|
55
|
-
# module BankAccountDepositCommmands
|
56
|
-
# def deposit_at_bank_office! amount, cashier_id
|
57
|
-
# deposited_to_cashier_event amount, cashier_id
|
58
|
-
# end
|
59
|
-
|
60
|
-
# def transfer_money_from_another_account! amount, from_account_number
|
61
|
-
# incoming_transfer_event amount,from_account_number
|
62
|
-
# end
|
63
|
-
# end
|
64
|
-
|
65
|
-
# class BankAccount
|
66
|
-
# include Sandthorn::AggregateRoot
|
67
|
-
|
68
|
-
# attr_reader :balance
|
69
|
-
# attr_reader :account_number
|
70
|
-
# attr_reader :current_interest_info
|
71
|
-
# attr_reader :account_creation_date
|
72
|
-
# attr_reader :unpaid_interest_balance
|
73
|
-
# attr_reader :last_interest_calculation
|
74
|
-
|
75
|
-
# def initialize *args
|
76
|
-
# account_number = args[0]
|
77
|
-
# interest_rate = args[1]
|
78
|
-
# creation_date = args[2]
|
79
|
-
|
80
|
-
# @current_interest_info = {}
|
81
|
-
# @current_interest_info[:interest_rate] = interest_rate
|
82
|
-
# @current_interest_info[:interest_valid_from] = creation_date
|
83
|
-
# @balance = 0
|
84
|
-
# @unpaid_interest_balance = 0
|
85
|
-
# @account_creation_date = creation_date
|
86
|
-
# @last_interest_calculation = creation_date
|
87
|
-
# end
|
88
|
-
|
89
|
-
# def changed_interest_rate_event new_interest_rate, interest_valid_from
|
90
|
-
# @current_interest_info[:interest_rate] = new_interest_rate
|
91
|
-
# @current_interest_info[:interest_valid_from] = interest_valid_from
|
92
|
-
# record_event
|
93
|
-
# end
|
94
|
-
|
95
|
-
# def added_unpaid_interest_event interest_amount, calculated_until
|
96
|
-
# @unpaid_interest_balance += interest_amount
|
97
|
-
# @last_interest_calculation = calculated_until
|
98
|
-
# record_event
|
99
|
-
# end
|
100
|
-
|
101
|
-
# def paid_out_unpaid_interest_balance_event interest_amount
|
102
|
-
# @unpaid_interest_balance -= interest_amount
|
103
|
-
# @balance += interest_amount
|
104
|
-
# record_event
|
105
|
-
# end
|
106
|
-
|
107
|
-
# def withdrew_amount_from_atm_event amount, atm_id
|
108
|
-
# @balance -= amount
|
109
|
-
# record_event
|
110
|
-
# end
|
111
|
-
|
112
|
-
# def withdrew_amount_from_cashier_event amount, cashier_id
|
113
|
-
# @balance -= amount
|
114
|
-
# record_event
|
115
|
-
# end
|
116
|
-
|
117
|
-
# def paid_with_visa_card_event amount, visa_card_transaction_id
|
118
|
-
# @balance -= amount
|
119
|
-
# record_event
|
120
|
-
# end
|
121
|
-
|
122
|
-
# def charged_cashier_withdrawal_fee_event amount
|
123
|
-
# @balance -= amount
|
124
|
-
# record_event
|
125
|
-
# end
|
126
|
-
|
127
|
-
# def deposited_to_cashier_event amount, cashier_id
|
128
|
-
# @balance = self.balance + amount
|
129
|
-
# record_event
|
130
|
-
# end
|
131
|
-
|
132
|
-
# def incoming_transfer_event amount, from_account_number
|
133
|
-
# current_balance = self.balance
|
134
|
-
# @balance = amount + current_balance
|
135
|
-
# record_event
|
136
|
-
# end
|
137
|
-
|
138
|
-
# end
|
139
|
-
|
140
|
-
# def a_test_account
|
141
|
-
# a = BankAccount.new "91503010111",0.031415, Date.new(2011,10,12)
|
142
|
-
# a.extend BankAccountDepositCommmands
|
143
|
-
# a.transfer_money_from_another_account! 90000, "FOOBAR"
|
144
|
-
# a.deposit_at_bank_office! 10000, "Lars Idorn"
|
145
|
-
|
146
|
-
# a.extend BankAccountVisaCardPurchasesCommands
|
147
|
-
# a.charge_card! 1000, "Starbucks Coffee"
|
148
|
-
|
149
|
-
# a.extend BankAccountInterestCommands
|
150
|
-
# a.calculate_interest!
|
151
|
-
# return a
|
152
|
-
# end
|
153
|
-
|
154
|
-
# #Tests part
|
155
|
-
# describe "when doing aggregate_find on an aggregate with a snapshot" do
|
156
|
-
# let(:aggregate) do
|
157
|
-
# a = a_test_account
|
158
|
-
# a.save
|
159
|
-
# a.extend Sandthorn::AggregateRootSnapshot
|
160
|
-
# a.aggregate_snapshot!
|
161
|
-
# a.save_snapshot
|
162
|
-
# a.charge_card! 9000, "Apple"
|
163
|
-
# a.save
|
164
|
-
# a
|
165
|
-
# end
|
166
|
-
# it "should be loaded with correct version" do
|
167
|
-
# org = aggregate
|
168
|
-
# loaded = BankAccount.find org.aggregate_id
|
169
|
-
# expect(loaded.balance).to eql org.balance
|
170
|
-
# end
|
171
|
-
# end
|
172
|
-
|
173
|
-
# describe 'when generating state on an aggregate root' do
|
174
|
-
|
175
|
-
# before(:each) do
|
176
|
-
# @original_account = a_test_account
|
177
|
-
# events = @original_account.aggregate_events
|
178
|
-
# @account = BankAccount.aggregate_build events
|
179
|
-
# @account.extend Sandthorn::AggregateRootSnapshot
|
180
|
-
# @account.aggregate_snapshot!
|
181
|
-
# end
|
182
|
-
|
183
|
-
# it 'account should have properties set' do
|
184
|
-
# expect(@account.balance).to eql 99000
|
185
|
-
# expect(@account.unpaid_interest_balance).to be > 1000
|
186
|
-
# end
|
187
|
-
|
188
|
-
|
189
|
-
# it 'should be able to load up from snapshot' do
|
190
|
-
|
191
|
-
# events = [aggregate: @account]
|
192
|
-
# loaded = BankAccount.aggregate_build events
|
193
|
-
|
194
|
-
# expect(loaded.balance).to eql(@original_account.balance)
|
195
|
-
# expect(loaded.account_number).to eql(@original_account.account_number)
|
196
|
-
# expect(loaded.current_interest_info).to eql(@original_account.current_interest_info)
|
197
|
-
# expect(loaded.account_creation_date).to eql(@original_account.account_creation_date)
|
198
|
-
# expect(loaded.unpaid_interest_balance).to eql(@original_account.unpaid_interest_balance)
|
199
|
-
# expect(loaded.last_interest_calculation).to eql(@original_account.last_interest_calculation)
|
200
|
-
# expect(loaded.aggregate_id).to eql(@original_account.aggregate_id)
|
201
|
-
# expect(loaded.aggregate_originating_version).to eql(@account.aggregate_originating_version)
|
202
|
-
|
203
|
-
# end
|
204
|
-
|
205
|
-
# end
|
206
|
-
|
207
|
-
# describe Sandthorn::AggregateRootSnapshot do
|
208
|
-
# let(:subject) { a_test_account.save.extend Sandthorn::AggregateRootSnapshot }
|
209
|
-
# context "when using :snapshot - method" do
|
210
|
-
# it "should return self" do
|
211
|
-
# expect(subject.snapshot).to eql subject
|
212
|
-
# end
|
213
|
-
# it "should raise SnapshotError if aggregate has unsaved events" do
|
214
|
-
# subject.paid_with_visa_card_event 2000, ""
|
215
|
-
# expect{subject.snapshot}.to raise_error Sandthorn::Errors::SnapshotError
|
216
|
-
# end
|
217
|
-
# end
|
218
|
-
# end
|
219
|
-
|
220
|
-
|
221
|
-
# describe 'when saving to repository' do
|
222
|
-
# let(:account) {a_test_account.extend Sandthorn::AggregateRootSnapshot}
|
223
|
-
|
224
|
-
# it 'should not raise an error if snapshot was created' do
|
225
|
-
# account.save
|
226
|
-
# account.aggregate_snapshot!
|
227
|
-
# expect(lambda {account.save_snapshot}).not_to raise_error
|
228
|
-
# end
|
229
|
-
# it 'should set aggregate_snapshot to nil' do
|
230
|
-
# account.save
|
231
|
-
# account.aggregate_snapshot!
|
232
|
-
# account.save_snapshot
|
233
|
-
# expect(account.aggregate_snapshot).to eql(nil)
|
234
|
-
# end
|
235
|
-
|
236
|
-
# it 'should raise error if trying to create snapshot before events are saved on object' do
|
237
|
-
# expect(lambda {account.aggregate_snapshot!}).to raise_error Sandthorn::Errors::SnapshotError
|
238
|
-
# end
|
239
|
-
|
240
|
-
# it 'should not raise an error if trying to create snapshot on object when events are saved' do
|
241
|
-
# account.save
|
242
|
-
# expect( lambda {account.aggregate_snapshot!}).not_to raise_error
|
243
|
-
# end
|
244
|
-
|
245
|
-
# it 'should get snapshot on account find when a snapshot is saved' do
|
246
|
-
|
247
|
-
# account.save
|
248
|
-
# account.aggregate_snapshot!
|
249
|
-
# account.save_snapshot
|
250
|
-
|
251
|
-
# loaded = BankAccount.find account.aggregate_id
|
252
|
-
|
253
|
-
# expect(loaded.balance).to eql(account.balance)
|
254
|
-
# expect(loaded.account_number).to eql(account.account_number)
|
255
|
-
# expect(loaded.current_interest_info).to eql(account.current_interest_info)
|
256
|
-
# expect(loaded.account_creation_date).to eql(account.account_creation_date)
|
257
|
-
# expect(loaded.unpaid_interest_balance).to eql(account.unpaid_interest_balance)
|
258
|
-
# expect(loaded.last_interest_calculation).to eql(account.last_interest_calculation)
|
259
|
-
# expect(loaded.aggregate_id).to eql(account.aggregate_id)
|
260
|
-
# expect(loaded.aggregate_originating_version).to eql(account.aggregate_originating_version)
|
261
|
-
|
262
|
-
# end
|
263
|
-
# end
|