sandthorn 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a0905a8e583c0c46aa86f5db5b1d9415afa991e
4
- data.tar.gz: 56ea78db0b5c871b8e807bbd53a6ae321db983cd
3
+ metadata.gz: 3e61d651d859798c915aa2cce28faece11f1d4c7
4
+ data.tar.gz: 592053f9f191cc595b7ccb6a517da939f881fb02
5
5
  SHA512:
6
- metadata.gz: a16f549f541a59451de1504b9c985fa629033010b77bfb3a8347a5d8b18afb9fc2c7a2ac89229eb9b86444b89fcec67d955de8453f91bceb79b98400b5fc1545
7
- data.tar.gz: 1540e391ae9dd007d33ef442d40984435f70746847d61a6b7f972ddde18f919d862bc589c9b381905b3ca77859f4cdabc1e6cd09fae294515396f9854e14bbe5
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
- unless aggregate_attribute_deltas.empty?
54
- method_name = caller_locations(1,1)[0].label.gsub(/block ?(.*) in /, "")
55
- increase_current_aggregate_version!
56
-
57
- data = {
58
- method_name: method_name,
59
- method_args: args,
60
- attribute_deltas: aggregate_attribute_deltas
61
- }
62
- trace_information = @aggregate_trace_information
63
- unless trace_information.nil? || trace_information.empty?
64
- data.merge!({ trace: trace_information })
65
- end
66
-
67
- @aggregate_events << ({
68
- aggregate_version: @aggregate_current_event_version,
69
- event_name: method_name,
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
@@ -1,3 +1,3 @@
1
1
  module Sandthorn
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -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(:dirty_obejct) {
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
- dirty_obejct.change_name "new_name"
96
- expect(dirty_obejct.name).to eql "new_name"
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(dirty_obejct.aggregate_events.length).to eql 1
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
- dirty_obejct.change_name "new_name"
105
- expect(dirty_obejct.aggregate_events.length).to eql 2
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
- dirty_obejct.change_sex "new_sex"
112
- expect(dirty_obejct.sex).to eql "new_sex"
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{dirty_obejct.change_writer "new_writer"}.to raise_error
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(dirty_obejct.save.aggregate_events.length).to eql 0
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(dirty_obejct.aggregate_originating_version).to eql 0
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(dirty_obejct.save.aggregate_originating_version).to eql 1
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) { dirty_obejct.save }
139
+ before(:each) { dirty_object.save }
138
140
  it "should find by id" do
139
- expect(DirtyClass.find(dirty_obejct.id).id).to eql dirty_obejct.id
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
- dirty_obejct.change_name("morgan").save
144
- expect(DirtyClass.find(dirty_obejct.id).name).to eql "morgan"
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(:dirty_obejct) {
159
+ let(:dirty_object) {
158
160
  o = DirtyClass.new :name => "old_value", :sex => "hen"
159
161
  o.save
160
162
  }
161
163
 
162
- let(:dirty_obejct_after_find) { DirtyClass.find dirty_obejct.id }
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
- dirty_obejct_after_find.change_name "new_name"
168
- expect(dirty_obejct_after_find.aggregate_events.last[:event_args][:attribute_deltas].first[:old_value]).to eql "old_value"
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
- dirty_obejct.change_name "new_name"
177
- expect(dirty_obejct.aggregate_events.last[:event_args][:attribute_deltas].first[:old_value]).to eql "old_value"
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
- dirty_obejct.change_name "new_name"
182
- expect(dirty_obejct.aggregate_events.last[:event_args][:attribute_deltas].last[:attribute_name]).not_to eql "aggregate_id"
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
- dirty_obejct.change_name "new_name"
187
- dirty_obejct.aggregate_events.each do |event|
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
- dirty_obejct.change_sex "hen"
196
- dirty_obejct.aggregate_events.each do |event|
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
- dirty_obejct.change_sex "shemale"
205
- expect(dirty_obejct.aggregate_events.last[:event_args][:attribute_deltas].first[:old_value]).to eql "hen"
206
- expect(dirty_obejct.aggregate_events.last[:event_args][:attribute_deltas].first[:new_value]).to eql "shemale"
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.1
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-09-29 00:00:00.000000000 Z
13
+ date: 2015-10-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler