sandthorn 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sandthorn/aggregate_root_base.rb +1 -1
- data/lib/sandthorn/version.rb +1 -1
- data/spec/aggregate_delta_spec.rb +9 -9
- data/spec/aggregate_root_spec.rb +2 -2
- data/spec/aggregate_snapshot_spec.rb +25 -25
- data/spec/complex_aggregate_spec.rb +5 -5
- data/spec/spec_helper.rb +0 -1
- data/spec/tracing_spec.rb +8 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 974b2f1521c09c03ea633790cdc1de37b47b46fb
|
4
|
+
data.tar.gz: 782de64f891f07fc78aff62cd53ebd70b9f05846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fc7334244668d45c4a39e730ab51dadb468267839638fe299b6c4ea131c964078d9dd2e73cfdd0fe23297ebfc257e7dfb6bab715f3a07996478c1d052f4de67
|
7
|
+
data.tar.gz: 86b770a90624c2cfed0a1ae9cae04f07f569c7ed3fb75c297cd5a53a9573180d1888b7f57ea3b39754f5c448bb8da7752e411e6f60346d19a168dc72a79e3d78
|
data/Gemfile.lock
CHANGED
@@ -49,7 +49,7 @@ module Sandthorn
|
|
49
49
|
aggregate_attribute_deltas = get_delta
|
50
50
|
|
51
51
|
unless aggregate_attribute_deltas.empty?
|
52
|
-
method_name = caller_locations(1,1)[0].label.gsub(
|
52
|
+
method_name = caller_locations(1,1)[0].label.gsub(/block ?(.*) in /, "")
|
53
53
|
increase_current_aggregate_version!
|
54
54
|
|
55
55
|
data = {
|
data/lib/sandthorn/version.rb
CHANGED
@@ -44,21 +44,21 @@ describe 'Property Delta Event Sourcing' do
|
|
44
44
|
|
45
45
|
it 'should be able to set name' do
|
46
46
|
person.change_name "Klabbarparen"
|
47
|
-
person.name.
|
47
|
+
expect(person.name).to eql("Klabbarparen")
|
48
48
|
#puts person.aggregate_events
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should be able to build from events' do
|
52
52
|
person.change_name "Klabbarparen"
|
53
53
|
builded = PersonTest.aggregate_build person.aggregate_events
|
54
|
-
builded.name.
|
55
|
-
builded.aggregate_id.
|
54
|
+
expect(builded.name).to eql(person.name)
|
55
|
+
expect(builded.aggregate_id).to eql(person.aggregate_id)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should not have any events when built up' do
|
59
59
|
person.change_name "Mattias"
|
60
60
|
builded = PersonTest.aggregate_build person.aggregate_events
|
61
|
-
builded.aggregate_events.
|
61
|
+
expect(builded.aggregate_events).to be_empty
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should detect change on array' do
|
@@ -66,8 +66,8 @@ describe 'Property Delta Event Sourcing' do
|
|
66
66
|
person.add_to_array "bar"
|
67
67
|
|
68
68
|
builded = PersonTest.aggregate_build person.aggregate_events
|
69
|
-
builded.my_array.
|
70
|
-
builded.my_array.
|
69
|
+
expect(builded.my_array).to include "Foo"
|
70
|
+
expect(builded.my_array).to include "bar"
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should detect change on hash' do
|
@@ -75,8 +75,8 @@ describe 'Property Delta Event Sourcing' do
|
|
75
75
|
person.add_to_hash :bar, "foo"
|
76
76
|
|
77
77
|
builded = PersonTest.aggregate_build person.aggregate_events
|
78
|
-
builded.my_hash[:foo].
|
79
|
-
builded.my_hash[:bar].
|
78
|
+
expect(builded.my_hash[:foo]).to eql("bar")
|
79
|
+
expect(builded.my_hash[:bar]).to eql("foo")
|
80
80
|
|
81
81
|
person.add_to_hash :foo, "BAR"
|
82
82
|
|
@@ -85,6 +85,6 @@ describe 'Property Delta Event Sourcing' do
|
|
85
85
|
#puts events
|
86
86
|
|
87
87
|
builded2 = PersonTest.aggregate_build person.aggregate_events
|
88
|
-
builded2.my_hash[:foo].
|
88
|
+
expect(builded2.my_hash[:foo]).to eql("BAR")
|
89
89
|
end
|
90
90
|
end
|
data/spec/aggregate_root_spec.rb
CHANGED
@@ -82,7 +82,7 @@ module Sandthorn
|
|
82
82
|
|
83
83
|
it "should get new_name" do
|
84
84
|
dirty_obejct.change_name "new_name"
|
85
|
-
dirty_obejct.name.
|
85
|
+
expect(dirty_obejct.name).to eql "new_name"
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should generate one event on new" do
|
@@ -98,7 +98,7 @@ module Sandthorn
|
|
98
98
|
context "when changing sex (attr)" do
|
99
99
|
it "should get new_sex" do
|
100
100
|
dirty_obejct.change_sex "new_sex"
|
101
|
-
dirty_obejct.sex.
|
101
|
+
expect(dirty_obejct.sex).to eql "new_sex"
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
@@ -181,16 +181,16 @@ describe 'when generating state on an aggregate root' do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
it 'account should have properties set' do
|
184
|
-
@account.balance.
|
185
|
-
@account.unpaid_interest_balance.
|
184
|
+
expect(@account.balance).to eql 99000
|
185
|
+
expect(@account.unpaid_interest_balance).to be > 1000
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'should store snapshot data in aggregate_snapshot' do
|
189
|
-
@account.aggregate_snapshot.
|
189
|
+
expect(@account.aggregate_snapshot).to be_a(Hash)
|
190
190
|
end
|
191
191
|
|
192
192
|
it 'should store aggregate_version in aggregate_snapshot' do
|
193
|
-
@account.aggregate_snapshot[:aggregate_version].
|
193
|
+
expect(@account.aggregate_snapshot[:aggregate_version]).to eql(@original_account.aggregate_current_event_version)
|
194
194
|
end
|
195
195
|
|
196
196
|
it 'should be able to load up from snapshot' do
|
@@ -198,14 +198,14 @@ describe 'when generating state on an aggregate root' do
|
|
198
198
|
events = [@account.aggregate_snapshot]
|
199
199
|
loaded = BankAccount.aggregate_build events
|
200
200
|
|
201
|
-
loaded.balance.
|
202
|
-
loaded.account_number.
|
203
|
-
loaded.current_interest_info.
|
204
|
-
loaded.account_creation_date.
|
205
|
-
loaded.unpaid_interest_balance.
|
206
|
-
loaded.last_interest_calculation.
|
207
|
-
loaded.aggregate_id.
|
208
|
-
loaded.aggregate_originating_version.
|
201
|
+
expect(loaded.balance).to eql(@original_account.balance)
|
202
|
+
expect(loaded.account_number).to eql(@original_account.account_number)
|
203
|
+
expect(loaded.current_interest_info).to eql(@original_account.current_interest_info)
|
204
|
+
expect(loaded.account_creation_date).to eql(@original_account.account_creation_date)
|
205
|
+
expect(loaded.unpaid_interest_balance).to eql(@original_account.unpaid_interest_balance)
|
206
|
+
expect(loaded.last_interest_calculation).to eql(@original_account.last_interest_calculation)
|
207
|
+
expect(loaded.aggregate_id).to eql(@original_account.aggregate_id)
|
208
|
+
expect(loaded.aggregate_originating_version).to eql(@account.aggregate_originating_version)
|
209
209
|
|
210
210
|
end
|
211
211
|
|
@@ -228,27 +228,27 @@ end
|
|
228
228
|
describe 'when saving to repository' do
|
229
229
|
let(:account) {a_test_account.extend Sandthorn::AggregateRootSnapshot}
|
230
230
|
it 'should raise an error if trying to save before creating a snapshot' do
|
231
|
-
lambda {account.save_snapshot}.
|
231
|
+
expect(lambda {account.save_snapshot}).to raise_error (Sandthorn::Errors::SnapshotError)
|
232
232
|
end
|
233
233
|
it 'should not raise an error if snapshot was created' do
|
234
234
|
account.save
|
235
235
|
account.aggregate_snapshot!
|
236
|
-
lambda {account.save_snapshot}.
|
236
|
+
expect(lambda {account.save_snapshot}).not_to raise_error
|
237
237
|
end
|
238
238
|
it 'should set aggregate_snapshot to nil' do
|
239
239
|
account.save
|
240
240
|
account.aggregate_snapshot!
|
241
241
|
account.save_snapshot
|
242
|
-
account.aggregate_snapshot.
|
242
|
+
expect(account.aggregate_snapshot).to eql(nil)
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'should raise error if trying to create snapshot before events are saved on object' do
|
246
|
-
lambda {account.aggregate_snapshot!}.
|
246
|
+
expect(lambda {account.aggregate_snapshot!}).to raise_error
|
247
247
|
end
|
248
248
|
|
249
249
|
it 'should not raise an error if trying to create snapshot on object when events are saved' do
|
250
250
|
account.save
|
251
|
-
lambda {account.aggregate_snapshot!}.
|
251
|
+
expect( lambda {account.aggregate_snapshot!}).not_to raise_error
|
252
252
|
end
|
253
253
|
|
254
254
|
it 'should get snapshot on account find when a snapshot is saved' do
|
@@ -259,14 +259,14 @@ describe 'when saving to repository' do
|
|
259
259
|
|
260
260
|
loaded = BankAccount.find account.aggregate_id
|
261
261
|
|
262
|
-
loaded.balance.
|
263
|
-
loaded.account_number.
|
264
|
-
loaded.current_interest_info.
|
265
|
-
loaded.account_creation_date.
|
266
|
-
loaded.unpaid_interest_balance.
|
267
|
-
loaded.last_interest_calculation.
|
268
|
-
loaded.aggregate_id.
|
269
|
-
loaded.aggregate_originating_version.
|
262
|
+
expect(loaded.balance).to eql(account.balance)
|
263
|
+
expect(loaded.account_number).to eql(account.account_number)
|
264
|
+
expect(loaded.current_interest_info).to eql(account.current_interest_info)
|
265
|
+
expect(loaded.account_creation_date).to eql(account.account_creation_date)
|
266
|
+
expect(loaded.unpaid_interest_balance).to eql(account.unpaid_interest_balance)
|
267
|
+
expect(loaded.last_interest_calculation).to eql(account.last_interest_calculation)
|
268
|
+
expect(loaded.aggregate_id).to eql(account.aggregate_id)
|
269
|
+
expect(loaded.aggregate_originating_version).to eql(account.aggregate_originating_version)
|
270
270
|
|
271
271
|
end
|
272
272
|
end
|
@@ -50,8 +50,8 @@ describe 'when using complex types in events' do
|
|
50
50
|
end
|
51
51
|
it 'should be able to build from events' do
|
52
52
|
aggr = IAmComplex.aggregate_build @events
|
53
|
-
aggr.a_date.
|
54
|
-
aggr.hello.
|
53
|
+
expect(aggr.a_date).to be_a(Date)
|
54
|
+
expect(aggr.hello).to be_a(Hello)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should detect hello changing' do
|
@@ -62,14 +62,14 @@ describe 'when using complex types in events' do
|
|
62
62
|
hello.change_me << "Otroligt"
|
63
63
|
aggr.set_hello! hello
|
64
64
|
builded = IAmComplex.aggregate_build aggr.aggregate_events
|
65
|
-
builded.hello.change_me.
|
66
|
-
builded.hello.change_me.
|
65
|
+
expect(builded.hello.change_me).to include "Fantastisk"
|
66
|
+
expect(builded.hello.change_me).to include "Otroligt"
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should detect foo_bar chaning in hello' 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
|
-
builded.hello.foo_bar.
|
73
|
+
expect(builded.hello.foo_bar).to eql "morgan"
|
74
74
|
end
|
75
75
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/tracing_spec.rb
CHANGED
@@ -42,19 +42,19 @@ describe "using a traced change" do
|
|
42
42
|
simple.aggregate_trace "123" do |traced|
|
43
43
|
traced.go
|
44
44
|
end
|
45
|
-
simple.events_with_trace_info.last[:trace].
|
45
|
+
expect(simple.events_with_trace_info.last[:trace]).to eql("123")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
context "when not tracing" do
|
49
49
|
it "should not have any trace event info at all on new" do
|
50
50
|
suspect = UsualSuspect.new "Ronny"
|
51
51
|
event = suspect.aggregate_events.first
|
52
|
-
event[:trace].
|
52
|
+
expect(event[:trace]).to be_nil
|
53
53
|
end
|
54
54
|
it "should not have any trace event info at all on regular event" do
|
55
55
|
suspect = UsualSuspect.new "Ronny"
|
56
56
|
event = suspect.aggregate_events.first
|
57
|
-
event[:trace].
|
57
|
+
expect(event[:trace]).to be_nil
|
58
58
|
end
|
59
59
|
end
|
60
60
|
context "when changing aggregate in a traced context" do
|
@@ -64,7 +64,7 @@ describe "using a traced change" do
|
|
64
64
|
s.charge_suspect_of_crime! "Theft"
|
65
65
|
end
|
66
66
|
event = suspect.events_with_trace_info.last
|
67
|
-
event[:trace].
|
67
|
+
expect(event[:trace]).to eql "Ture Sventon"
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should record optional other tracing information" do
|
@@ -73,7 +73,7 @@ describe "using a traced change" do
|
|
73
73
|
s.charge_suspect_of_crime! "Murder"
|
74
74
|
end
|
75
75
|
event = suspect.events_with_trace_info.last
|
76
|
-
event[:trace].
|
76
|
+
expect(event[:trace]).to eql trace_info
|
77
77
|
end
|
78
78
|
end
|
79
79
|
context "when initializing a new aggregate in a traced context" do
|
@@ -81,7 +81,7 @@ describe "using a traced change" do
|
|
81
81
|
UsualSuspect.aggregate_trace "Ture Sventon" do
|
82
82
|
suspect = UsualSuspect.new("Sonny").extend Sandthorn::EventInspector
|
83
83
|
event = suspect.events_with_trace_info.first
|
84
|
-
event[:trace].
|
84
|
+
expect(event[:trace]).to eql "Ture Sventon"
|
85
85
|
end
|
86
86
|
end
|
87
87
|
it "should record tracing for all events in the trace block" do
|
@@ -90,7 +90,7 @@ describe "using a traced change" do
|
|
90
90
|
suspect = UsualSuspect.new("Sonny").extend Sandthorn::EventInspector
|
91
91
|
suspect.charge_suspect_of_crime! "Hit and run"
|
92
92
|
event = suspect.events_with_trace_info.last
|
93
|
-
event[:trace].
|
93
|
+
expect(event[:trace]).to eql trace_info
|
94
94
|
end
|
95
95
|
end
|
96
96
|
it "should record tracing for all events in the trace block" do
|
@@ -99,7 +99,7 @@ describe "using a traced change" do
|
|
99
99
|
suspect = UsualSuspect.new("Conny").extend Sandthorn::EventInspector
|
100
100
|
suspect.charge_suspect_of_crime! "Desception"
|
101
101
|
event = suspect.events_with_trace_info.last
|
102
|
-
event[:trace].
|
102
|
+
expect(event[:trace]).to eql trace_info
|
103
103
|
end
|
104
104
|
end
|
105
105
|
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: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Krantz
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|