sandthorn 0.9.1 → 0.9.2
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 +4 -4
- data/lib/sandthorn/aggregate_root_base.rb +17 -20
- data/lib/sandthorn/version.rb +1 -1
- data/spec/aggregate_root_spec.rb +52 -33
- 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: 3e61d651d859798c915aa2cce28faece11f1d4c7
|
4
|
+
data.tar.gz: 592053f9f191cc595b7ccb6a517da939f881fb02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c6fd3e0611518d6ad6d6383bcd99a0b24bf09bca5ccc4f59da46299a83f6e4c19b503cfda4f656ecd813f4a56e3aa6381d3e55cd6abec427c7ce4a55d59564
|
7
|
+
data.tar.gz: f7b104d6f9302685981e39e9d21e9eff0bb60f74bffb5e0fd05717e1984d934e36c7751317c5e853046dad5ccb8b29a8b461838d6293f9fe4b683f7da2df019b
|
@@ -50,26 +50,23 @@ module Sandthorn
|
|
50
50
|
def commit *args
|
51
51
|
aggregate_attribute_deltas = get_delta
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
trace_information
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
event_args: data
|
71
|
-
})
|
72
|
-
end
|
53
|
+
method_name = caller_locations(1,1)[0].label.gsub(/block ?(.*) in /, "")
|
54
|
+
increase_current_aggregate_version!
|
55
|
+
data = {
|
56
|
+
method_name: method_name,
|
57
|
+
method_args: args,
|
58
|
+
attribute_deltas: aggregate_attribute_deltas
|
59
|
+
}
|
60
|
+
trace_information = @aggregate_trace_information
|
61
|
+
unless trace_information.nil? || trace_information.empty?
|
62
|
+
data.merge!({ trace: trace_information })
|
63
|
+
end
|
64
|
+
|
65
|
+
@aggregate_events << ({
|
66
|
+
aggregate_version: @aggregate_current_event_version,
|
67
|
+
event_name: method_name,
|
68
|
+
event_args: data
|
69
|
+
})
|
73
70
|
|
74
71
|
self
|
75
72
|
end
|
data/lib/sandthorn/version.rb
CHANGED
data/spec/aggregate_root_spec.rb
CHANGED
@@ -35,7 +35,9 @@ module Sandthorn
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
def no_state_change_only_empty_event
|
39
|
+
commit
|
40
|
+
end
|
39
41
|
end
|
40
42
|
|
41
43
|
describe "::event_store" do
|
@@ -74,7 +76,7 @@ module Sandthorn
|
|
74
76
|
|
75
77
|
|
76
78
|
describe "when making a change on a aggregate" do
|
77
|
-
let(:
|
79
|
+
let(:dirty_object) {
|
78
80
|
o = DirtyClass.new
|
79
81
|
o
|
80
82
|
}
|
@@ -92,56 +94,56 @@ module Sandthorn
|
|
92
94
|
context "when changing name (attr_reader)" do
|
93
95
|
|
94
96
|
it "should get new_name" do
|
95
|
-
|
96
|
-
expect(
|
97
|
+
dirty_object.change_name "new_name"
|
98
|
+
expect(dirty_object.name).to eql "new_name"
|
97
99
|
end
|
98
100
|
|
99
101
|
it "should generate one event on new" do
|
100
|
-
expect(
|
102
|
+
expect(dirty_object.aggregate_events.length).to eql 1
|
101
103
|
end
|
102
104
|
|
103
105
|
it "should generate 2 events new and change_name" do
|
104
|
-
|
105
|
-
expect(
|
106
|
+
dirty_object.change_name "new_name"
|
107
|
+
expect(dirty_object.aggregate_events.length).to eql 2
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
111
|
context "when changing sex (attr)" do
|
110
112
|
it "should get new_sex" do
|
111
|
-
|
112
|
-
expect(
|
113
|
+
dirty_object.change_sex "new_sex"
|
114
|
+
expect(dirty_object.sex).to eql "new_sex"
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
116
118
|
context "when changing writer (attr_writer)" do
|
117
119
|
it "should raise error" do
|
118
|
-
expect{
|
120
|
+
expect{dirty_object.change_writer "new_writer"}.to raise_error
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
122
124
|
context "save" do
|
123
125
|
it "should not have events on aggregete after save" do
|
124
|
-
expect(
|
126
|
+
expect(dirty_object.save.aggregate_events.length).to eql 0
|
125
127
|
end
|
126
128
|
|
127
129
|
it "should have aggregate_originating_version == 0 pre save" do
|
128
|
-
expect(
|
130
|
+
expect(dirty_object.aggregate_originating_version).to eql 0
|
129
131
|
end
|
130
132
|
|
131
133
|
it "should have aggregate_originating_version == 1 post save" do
|
132
|
-
expect(
|
134
|
+
expect(dirty_object.save.aggregate_originating_version).to eql 1
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
136
138
|
context "find" do
|
137
|
-
before(:each) {
|
139
|
+
before(:each) { dirty_object.save }
|
138
140
|
it "should find by id" do
|
139
|
-
expect(DirtyClass.find(
|
141
|
+
expect(DirtyClass.find(dirty_object.id).id).to eql dirty_object.id
|
140
142
|
end
|
141
143
|
|
142
144
|
it "should hold changed name" do
|
143
|
-
|
144
|
-
expect(DirtyClass.find(
|
145
|
+
dirty_object.change_name("morgan").save
|
146
|
+
expect(DirtyClass.find(dirty_object.id).name).to eql "morgan"
|
145
147
|
end
|
146
148
|
|
147
149
|
it "should raise error if trying to find id that not exist" do
|
@@ -154,18 +156,18 @@ module Sandthorn
|
|
154
156
|
|
155
157
|
describe "event data" do
|
156
158
|
|
157
|
-
let(:
|
159
|
+
let(:dirty_object) {
|
158
160
|
o = DirtyClass.new :name => "old_value", :sex => "hen"
|
159
161
|
o.save
|
160
162
|
}
|
161
163
|
|
162
|
-
let(:
|
164
|
+
let(:dirty_object_after_find) { DirtyClass.find dirty_object.id }
|
163
165
|
|
164
166
|
context "after find" do
|
165
167
|
|
166
168
|
it "should set the old_value on the event" do
|
167
|
-
|
168
|
-
expect(
|
169
|
+
dirty_object_after_find.change_name "new_name"
|
170
|
+
expect(dirty_object_after_find.aggregate_events.last[:event_args][:attribute_deltas].first[:old_value]).to eql "old_value"
|
169
171
|
end
|
170
172
|
|
171
173
|
end
|
@@ -173,18 +175,18 @@ module Sandthorn
|
|
173
175
|
context "old_value should be set" do
|
174
176
|
|
175
177
|
it "should set the old_value on the event" do
|
176
|
-
|
177
|
-
expect(
|
178
|
+
dirty_object.change_name "new_name"
|
179
|
+
expect(dirty_object.aggregate_events.last[:event_args][:attribute_deltas].first[:old_value]).to eql "old_value"
|
178
180
|
end
|
179
181
|
|
180
182
|
it "should not change aggregate_id" do
|
181
|
-
|
182
|
-
expect(
|
183
|
+
dirty_object.change_name "new_name"
|
184
|
+
expect(dirty_object.aggregate_events.last[:event_args][:attribute_deltas].last[:attribute_name]).not_to eql "aggregate_id"
|
183
185
|
end
|
184
186
|
|
185
187
|
it "should not change sex attribute if sex method is not runned" do
|
186
|
-
|
187
|
-
|
188
|
+
dirty_object.change_name "new_name"
|
189
|
+
dirty_object.aggregate_events.each do |event|
|
188
190
|
event[:event_args][:attribute_deltas].each do |attribute_delta|
|
189
191
|
expect(attribute_delta[:attribute_name]).not_to eql "sex"
|
190
192
|
end
|
@@ -192,8 +194,8 @@ module Sandthorn
|
|
192
194
|
end
|
193
195
|
|
194
196
|
it "should not change sex attribute if sex attribute is the same" do
|
195
|
-
|
196
|
-
|
197
|
+
dirty_object.change_sex "hen"
|
198
|
+
dirty_object.aggregate_events.each do |event|
|
197
199
|
event[:event_args][:attribute_deltas].each do |attribute_delta|
|
198
200
|
expect(attribute_delta[:attribute_name]).not_to eql "sex"
|
199
201
|
end
|
@@ -201,11 +203,28 @@ module Sandthorn
|
|
201
203
|
end
|
202
204
|
|
203
205
|
it "should set old_value and new_value on sex change" do
|
204
|
-
|
205
|
-
expect(
|
206
|
-
expect(
|
206
|
+
dirty_object.change_sex "shemale"
|
207
|
+
expect(dirty_object.aggregate_events.last[:event_args][:attribute_deltas].first[:old_value]).to eql "hen"
|
208
|
+
expect(dirty_object.aggregate_events.last[:event_args][:attribute_deltas].first[:new_value]).to eql "shemale"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "events should be created event if no state change is made" do
|
214
|
+
let(:dirty_object) do
|
215
|
+
DirtyClass.new.save.tap do |o|
|
216
|
+
o.no_state_change_only_empty_event
|
207
217
|
end
|
208
218
|
end
|
219
|
+
|
220
|
+
it "should have the event no_state_change_only_empty_event" do
|
221
|
+
expect(dirty_object.aggregate_events.first[:event_name]).to eql("no_state_change_only_empty_event")
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should have attribute_deltas set to empty array" do
|
225
|
+
expect(dirty_object.aggregate_events.first[:event_args][:attribute_deltas]).to eql([])
|
226
|
+
end
|
227
|
+
|
209
228
|
end
|
210
229
|
end
|
211
|
-
end
|
230
|
+
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.9.
|
4
|
+
version: 0.9.2
|
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: 2015-
|
13
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|