sandthorn 0.13.0 → 1.0.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.
@@ -25,7 +25,7 @@ class IAmComplex
25
25
 
26
26
  def set_foo_bar_on_hello value
27
27
  @hello.set_foo_bar value
28
- commit value
28
+ commit
29
29
  end
30
30
 
31
31
 
@@ -36,7 +36,7 @@ class IAmComplex
36
36
  private
37
37
  def set_hello_event hello
38
38
  @hello = hello
39
- commit hello
39
+ commit
40
40
  end
41
41
 
42
42
  end
@@ -49,16 +49,12 @@ module Sandthorn
49
49
  end
50
50
 
51
51
  it "should have created an created_event" do
52
- expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_name]).to eql "created_event"
53
- end
54
-
55
- it "should have set the method_args to create_name" do
56
- expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_args][:method_args].first).to eql "create_name"
52
+ expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_name]).to eql "created_event"
57
53
  end
58
54
 
59
55
  it "should have set the attribute_delta name" do
60
- expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_args][:attribute_deltas].last[:attribute_name]).to eql "name"
61
- expect(Sandthorn.get_aggregate_events(ConstructorEventsSpec, aggregate_id).first[:event_args][:attribute_deltas].last[:new_value]).to eql "create_name"
56
+ expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_data][:attribute_deltas].last[:attribute_name]).to eql "name"
57
+ expect(Sandthorn.find(aggregate_id, ConstructorEventsSpec).first[:event_data][:attribute_deltas].last[:new_value]).to eql "create_name"
62
58
  end
63
59
  end
64
60
  end
@@ -10,7 +10,7 @@ module Sandthorn
10
10
  "sequence_number":114,
11
11
  "event_name":"new",
12
12
  "timestamp":"2014-08-16 20:02:05 UTC",
13
- "event_args":{"method_name":"new",
13
+ "event_data":{"method_name":"new",
14
14
  "method_args":[{"name":"Hahah",
15
15
  "price":"50",
16
16
  "stock_status":"outofstock"}],
@@ -42,7 +42,7 @@ module Sandthorn
42
42
  aggregate_version
43
43
  timestamp
44
44
  event_name
45
- event_args
45
+ event_data
46
46
  method_args
47
47
  trace
48
48
  )
@@ -75,7 +75,7 @@ module Sandthorn
75
75
 
76
76
  describe "a delta" do
77
77
  let(:wrapped_delta) { subject.attribute_deltas.first }
78
- let(:raw_delta) { subject[:event_args][:attribute_deltas].first }
78
+ let(:raw_delta) { subject[:event_data][:attribute_deltas].first }
79
79
  describe "#attribute_name" do
80
80
  it "has the same value as the raw hash" do
81
81
  expect(wrapped_delta.attribute_name).to eq(raw_delta[:attribute_name])
@@ -10,7 +10,6 @@ require "ap"
10
10
  require "bundler"
11
11
  require "sandthorn_driver_sequel"
12
12
  require "support/custom_matchers"
13
-
14
13
  Bundler.require
15
14
 
16
15
  module Helpers
@@ -29,30 +28,34 @@ RSpec.configure do |config|
29
28
  # the seed, which is printed after each run.
30
29
  # --seed 1234
31
30
  config.order = 'random'
32
- config.before(:each) { sqlite_store_setup }
31
+ config.before(:all) {
32
+ sqlite_store_setup
33
+ }
34
+
35
+ config.before(:each) {
36
+ migrator = SandthornDriverSequel::Migration.new url: url
37
+ migrator.send(:clear_for_test)
38
+ }
33
39
 
34
- config.after(:each) do
40
+ config.after(:all) do
35
41
  Sandthorn.event_stores.default_store.driver.instance_variable_get(:@db).disconnect
36
42
  end
37
43
  end
38
44
 
39
- def spec_db
45
+ def url
40
46
  "sqlite://spec/db/sequel_driver.sqlite3"
41
47
  end
42
48
  def sqlite_store_setup
43
- url = spec_db
49
+
50
+ SandthornDriverSequel.migrate_db url: url
44
51
 
45
52
  driver = SandthornDriverSequel.driver_from_url(url: url) do |conf|
46
53
  conf.event_serializer = Proc.new { |data| YAML::dump(data) }
47
54
  conf.event_deserializer = Proc.new { |data| YAML::load(data) }
48
- conf.snapshot_serializer = Proc.new { |data| YAML::dump(data) }
49
- conf.snapshot_deserializer = Proc.new { |data| YAML::load(data) }
50
55
  end
51
-
56
+
52
57
  Sandthorn.configure do |c|
53
58
  c.event_store = driver
54
59
  end
55
- migrator = SandthornDriverSequel::Migration.new url: url
56
- SandthornDriverSequel.migrate_db url: url
57
- migrator.send(:clear_for_test)
60
+
58
61
  end
@@ -14,6 +14,10 @@ module Sandthorn
14
14
  end
15
15
 
16
16
  describe "::stateless_events" do
17
+
18
+ let(:args) do
19
+ {first: "first", other: [1,2,3]}
20
+ end
17
21
 
18
22
  context "interface" do
19
23
 
@@ -30,15 +34,11 @@ module Sandthorn
30
34
  end
31
35
 
32
36
  before do
33
- StatelessEventsSpec.one_event(subject.aggregate_id, args, 1)
34
- end
35
-
36
- let(:args) do
37
- {first: "first", other: [1,2,3]}
37
+ StatelessEventsSpec.one_event(subject.aggregate_id, args)
38
38
  end
39
39
 
40
40
  let(:last_event) do
41
- Sandthorn.get_aggregate_events(StatelessEventsSpec, subject.aggregate_id).last
41
+ Sandthorn.find(subject.aggregate_id, StatelessEventsSpec).last
42
42
  end
43
43
 
44
44
  let(:reloaded_subject) do
@@ -49,13 +49,8 @@ module Sandthorn
49
49
  expect(last_event[:event_name]).to eql "one_event"
50
50
  end
51
51
 
52
- it "should not have any deltas in event" do
53
- expect(last_event[:event_args][:attribute_deltas]).to eql []
54
- end
55
-
56
- it "should store event arguments" do
57
- expect(last_event[:event_args][:method_args].first).to eql(args)
58
- expect(last_event[:event_args][:method_args].last).to eql(1)
52
+ it "should have staeless data in deltas in event" do
53
+ expect(last_event[:event_data][:attribute_deltas]).to eql ([{:attribute_name=>"first", :old_value => nil, :new_value => "first"}, { :attribute_name => "other", :old_value => nil, :new_value => [1, 2, 3]}])
59
54
  end
60
55
 
61
56
  it "should have same name attribute after reload" do
@@ -66,13 +61,13 @@ module Sandthorn
66
61
  context "when adding stateless_events to none existing aggregate" do
67
62
 
68
63
  before do
69
- StatelessEventsSpec.one_event(aggregate_id, "argument_data")
64
+ StatelessEventsSpec.one_event(aggregate_id, args)
70
65
  end
71
66
 
72
67
  let(:aggregate_id) {"none_existing_aggregate_id"}
73
68
 
74
69
  let(:events) do
75
- Sandthorn.get_aggregate_events(StatelessEventsSpec, aggregate_id)
70
+ Sandthorn.find aggregate_id, StatelessEventsSpec
76
71
  end
77
72
 
78
73
  it "should store the stateless event as the first event" do
@@ -88,5 +83,26 @@ module Sandthorn
88
83
  end
89
84
  end
90
85
 
86
+ context "overriding properties with stateless data" do
87
+ let(:subject) do
88
+ StatelessEventsSpec.new("name").save
89
+ end
90
+
91
+ let(:reloaded_subject) do
92
+ StatelessEventsSpec.find subject.aggregate_id
93
+ end
94
+
95
+ let(:args) do
96
+ {name: "ghost"}
97
+ end
98
+
99
+ before do
100
+ StatelessEventsSpec.one_event(subject.aggregate_id, args)
101
+ end
102
+
103
+ it "should override the name via the stateless event" do
104
+ expect(subject.name).not_to eql(reloaded_subject.name)
105
+ end
106
+ end
91
107
  end
92
108
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'sandthorn/event_inspector'
3
- require 'sandthorn/aggregate_root_snapshot'
4
3
 
5
4
  class UsualSuspect
6
5
  include Sandthorn::AggregateRoot
@@ -17,7 +16,7 @@ class UsualSuspect
17
16
  private
18
17
  def suspect_was_charged crime_name
19
18
  @charges << crime_name
20
- record_event crime_name
19
+ record_event
21
20
  end
22
21
  end
23
22
 
@@ -36,25 +35,24 @@ describe "using a traced change" do
36
35
  it "should record tracing if specified" do
37
36
  simple = Simple.new
38
37
  simple.extend Sandthorn::EventInspector
39
- simple.extend Sandthorn::AggregateRootSnapshot
40
38
 
41
39
  simple.extend Go
42
40
  simple.aggregate_trace "123" do |traced|
43
41
  traced.go
44
42
  end
45
- expect(simple.events_with_trace_info.last[:trace]).to eql("123")
43
+ expect(simple.events_with_trace_info.last[:event_metadata]).to eql("123")
46
44
  end
47
45
  end
48
46
  context "when not tracing" do
49
47
  it "should not have any trace event info at all on new" do
50
48
  suspect = UsualSuspect.new "Ronny"
51
49
  event = suspect.aggregate_events.first
52
- expect(event[:trace]).to be_nil
50
+ expect(event[:event_metadata]).to be_nil
53
51
  end
54
52
  it "should not have any trace event info at all on regular event" do
55
53
  suspect = UsualSuspect.new "Ronny"
56
54
  event = suspect.aggregate_events.first
57
- expect(event[:trace]).to be_nil
55
+ expect(event[:event_metadata]).to be_nil
58
56
  end
59
57
  end
60
58
  context "when changing aggregate in a traced context" do
@@ -64,7 +62,7 @@ describe "using a traced change" do
64
62
  s.charge_suspect_of_crime! "Theft"
65
63
  end
66
64
  event = suspect.events_with_trace_info.last
67
- expect(event[:trace]).to eql "Ture Sventon"
65
+ expect(event[:event_metadata]).to eql "Ture Sventon"
68
66
  end
69
67
 
70
68
  it "should record optional other tracing information" do
@@ -73,7 +71,7 @@ describe "using a traced change" do
73
71
  s.charge_suspect_of_crime! "Murder"
74
72
  end
75
73
  event = suspect.events_with_trace_info.last
76
- expect(event[:trace]).to eql trace_info
74
+ expect(event[:event_metadata]).to eql trace_info
77
75
  end
78
76
  end
79
77
  context "when initializing a new aggregate in a traced context" do
@@ -81,7 +79,7 @@ describe "using a traced change" do
81
79
  UsualSuspect.aggregate_trace "Ture Sventon" do
82
80
  suspect = UsualSuspect.new("Sonny").extend Sandthorn::EventInspector
83
81
  event = suspect.events_with_trace_info.first
84
- expect(event[:trace]).to eql "Ture Sventon"
82
+ expect(event[:event_metadata]).to eql "Ture Sventon"
85
83
  end
86
84
  end
87
85
  it "should record tracing for all events in the trace block" do
@@ -90,7 +88,7 @@ describe "using a traced change" do
90
88
  suspect = UsualSuspect.new("Sonny").extend Sandthorn::EventInspector
91
89
  suspect.charge_suspect_of_crime! "Hit and run"
92
90
  event = suspect.events_with_trace_info.last
93
- expect(event[:trace]).to eql trace_info
91
+ expect(event[:event_metadata]).to eql trace_info
94
92
  end
95
93
  end
96
94
  it "should record tracing for all events in the trace block" do
@@ -99,7 +97,7 @@ describe "using a traced change" do
99
97
  suspect = UsualSuspect.new("Conny").extend Sandthorn::EventInspector
100
98
  suspect.charge_suspect_of_crime! "Desception"
101
99
  event = suspect.events_with_trace_info.last
102
- expect(event[:trace]).to eql trace_info
100
+ expect(event[:event_metadata]).to eql trace_info
103
101
  end
104
102
  end
105
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: 0.13.0
4
+ version: 1.0.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: 2016-04-13 00:00:00.000000000 Z
13
+ date: 2017-05-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -158,14 +158,14 @@ dependencies:
158
158
  requirements:
159
159
  - - ">="
160
160
  - !ruby/object:Gem::Version
161
- version: '3.1'
161
+ version: '4.0'
162
162
  type: :development
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
166
  - - ">="
167
167
  - !ruby/object:Gem::Version
168
- version: '3.1'
168
+ version: '4.0'
169
169
  description: Event sourcing gem
170
170
  email:
171
171
  - lars.krantz@alaz.se
@@ -213,9 +213,7 @@ files:
213
213
  - spec/event_inspector_spec.rb
214
214
  - spec/event_spec.rb
215
215
  - spec/event_stores_spec.rb
216
- - spec/get_events_spec.rb
217
216
  - spec/initialize_signature_change_spec.rb
218
- - spec/sandthorn_spec.rb
219
217
  - spec/spec_helper.rb
220
218
  - spec/stateless_events_spec.rb
221
219
  - spec/support/custom_matchers.rb
@@ -240,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
238
  version: '0'
241
239
  requirements: []
242
240
  rubyforge_project:
243
- rubygems_version: 2.4.3
241
+ rubygems_version: 2.6.11
244
242
  signing_key:
245
243
  specification_version: 4
246
244
  summary: Event sourcing gem
@@ -259,11 +257,8 @@ test_files:
259
257
  - spec/event_inspector_spec.rb
260
258
  - spec/event_spec.rb
261
259
  - spec/event_stores_spec.rb
262
- - spec/get_events_spec.rb
263
260
  - spec/initialize_signature_change_spec.rb
264
- - spec/sandthorn_spec.rb
265
261
  - spec/spec_helper.rb
266
262
  - spec/stateless_events_spec.rb
267
263
  - spec/support/custom_matchers.rb
268
264
  - spec/tracing_spec.rb
269
- has_rdoc:
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class AnAggregate
4
- include Sandthorn::AggregateRoot
5
- end
6
-
7
- class AnotherAggregate
8
- include Sandthorn::AggregateRoot
9
- event_store :should_override_this
10
- end
11
-
12
- describe Sandthorn do
13
-
14
- describe "::get_events" do
15
- context "when getting events using Sandthorn.get_events for an aggregate type" do
16
- before do
17
- AnAggregate.new.save
18
- end
19
- let(:events) { Sandthorn.get_events aggregate_types: [AnAggregate] }
20
- it "should return events" do
21
- expect(events).to_not be_empty
22
- end
23
- end
24
-
25
- context "when there are many event stores configured" do
26
- before do
27
- setup_secondary_db
28
- end
29
-
30
- let!(:agg) do
31
- AnAggregate.new.save
32
- end
33
-
34
- let!(:other_agg) do
35
- AnotherAggregate.new.save
36
- end
37
-
38
- shared_examples(:default_event_store) do
39
- it "returns events from the default event store" do
40
- events = Sandthorn.get_events
41
- expect(events).to all(have_aggregate_type("AnAggregate"))
42
- end
43
- end
44
-
45
- context "when no explicit event store is used" do
46
- it_behaves_like :default_event_store
47
- end
48
-
49
- context "when given an explicit event store" do
50
- context "and that event store exists" do
51
- it "returns events from the chosen event store" do
52
- events = Sandthorn.get_events(event_store: :other)
53
- expect(events).to all(have_aggregate_type("AnotherAggregate"))
54
- end
55
- end
56
-
57
- context "and that event store does not exist" do
58
- it_behaves_like :default_event_store
59
- end
60
- end
61
-
62
- end
63
- end
64
-
65
- def setup_secondary_db
66
- url = "sqlite://spec/db/other_db.sqlite3"
67
- driver = SandthornDriverSequel.driver_from_url(url: url)
68
- Sandthorn.event_stores.add(:other, driver)
69
- Sandthorn.event_stores.map_types(other: [AnotherAggregate])
70
- migrator = SandthornDriverSequel::Migration.new url: url
71
- SandthornDriverSequel.migrate_db url: url
72
- migrator.send(:clear_for_test)
73
- end
74
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class AnAggregate
4
- include Sandthorn::AggregateRoot
5
- def touch; touched; end
6
- def touched; commit; end
7
- end
8
-
9
- module Outer
10
- module Inner
11
- class OtherAggregate < AnAggregate; end
12
- end
13
- end
14
-
15
- describe Sandthorn do
16
- before(:each) {
17
- @aggregate = AnAggregate.new
18
- @aggregate.touch
19
- @aggregate.save
20
- }
21
-
22
- describe "::obsolete_snapshot" do
23
- it "retrieves a list of obsolete snapshots" do
24
- obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 0
25
- expect(obsolete_aggregates).to_not be_empty
26
- end
27
-
28
- it "accepts a block that is applied to each aggregate" do
29
- obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 0
30
- expect do |block|
31
- Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 0, &block
32
- end.to yield_successive_args(*obsolete_aggregates)
33
- end
34
-
35
- it "only retrieves aggregates older than min_event_distance" do
36
- obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [AnAggregate], min_event_distance: 10
37
- expect(obsolete_aggregates).to be_empty
38
- end
39
-
40
- context "when the aggregate has been declared in a module" do
41
-
42
- before do
43
- Outer::Inner::OtherAggregate.new.tap do |agg|
44
- agg.touch
45
- agg.save
46
- end
47
- end
48
-
49
- it "doesn't crash" do
50
- obsolete_aggregates = Sandthorn.obsolete_snapshots type_names: [Outer::Inner::OtherAggregate], min_event_distance: 0
51
- expect(obsolete_aggregates).to all(be_a_kind_of(Outer::Inner::OtherAggregate))
52
- end
53
- end
54
- end
55
-
56
- describe "::save_snapshot" do
57
- context "when a keyword is missing" do
58
- it "raises an ArgumentError" do
59
- expect { Sandthorn.save_snapshot }.to raise_error(ArgumentError)
60
- end
61
- end
62
- end
63
-
64
- describe "::configure" do
65
-
66
- it "should respond_to map_types=" do
67
- Sandthorn.configure do |conf|
68
- expect(conf).to respond_to(:map_types=)
69
- end
70
- end
71
- end
72
- end