sandthorn_driver_sequel 4.0.0 → 4.1.0

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: 733436ed1a28c227cd7f4af61f0e988d3596d4cc
4
- data.tar.gz: 3fb7675715543044914b2490a5322855d4d3163b
3
+ metadata.gz: 0a1fe00053ffc5348f2d2f32af95a97a94a6c282
4
+ data.tar.gz: 67e545d052af2a9633970b469cbeb1c68287bc46
5
5
  SHA512:
6
- metadata.gz: 1b8bdba85c255968f5c076780ee5f2de0ade21168d91ad3e45c8b2ee965d3c5b1fe14cb23cb3460bf4ee4b3dad2dd0b5ceb1cd59e8223e542e709cfee5e8ede7
7
- data.tar.gz: 9850c19545a557071a6bb616d08e2d01fdfd281db913e41d1de1cf4c9ccfe5aa79f31b05a8eae2df3c3f9c86555c13e3fa98ba41d120f674f9cedbb1fa5269e1
6
+ metadata.gz: 0c154c8ca437483f418464fa3c5d6fa279153dc173d26634824269d4e982c7b45df7f28f24c849f6e68bc58ea37051b14e2a0cea7a83eef7642bb7a7c604066d
7
+ data.tar.gz: a808bcdefe4bbf12872d63ad1b28a03856d91e51d7a54d47654d8f7acacf9808e44d69214e0629a1a8a6ce7ffe4062cf8f1eb4ecdb67fdb89271c6de82ee65f6
@@ -20,11 +20,12 @@ module SandthornDriverSequel
20
20
  aggregate.save
21
21
  end
22
22
 
23
- def find_events_by_aggregate_id(aggregate_id)
23
+ def find_events_by_aggregate_id(aggregate_id, after_aggregate_version = 0)
24
24
  aggregate_version = Sequel.qualify(storage.events_table_name, :aggregate_version)
25
25
  wrap(storage.events
26
26
  .join(storage.aggregates_table_name, id: :aggregate_table_id)
27
27
  .where(aggregate_id: aggregate_id)
28
+ .where(aggregate_version > after_aggregate_version)
28
29
  .select(
29
30
  :sequence_number,
30
31
  :aggregate_id,
@@ -36,8 +36,8 @@ module SandthornDriverSequel
36
36
  end
37
37
  end
38
38
 
39
- def find aggregate_id, aggregate_type
40
- aggregate_events(aggregate_id)
39
+ def find aggregate_id, aggregate_type, after_aggregate_version = 0
40
+ aggregate_events(aggregate_id, after_aggregate_version)
41
41
  end
42
42
 
43
43
  def get_events(*args)
@@ -49,10 +49,10 @@ module SandthornDriverSequel
49
49
 
50
50
  private
51
51
 
52
- def aggregate_events(aggregate_id)
52
+ def aggregate_events(aggregate_id, after_aggregate_version = 0)
53
53
  driver.execute do |db|
54
54
  event_access = get_event_access(db)
55
- event_access.find_events_by_aggregate_id(aggregate_id)
55
+ event_access.find_events_by_aggregate_id(aggregate_id, after_aggregate_version)
56
56
  end
57
57
  end
58
58
 
@@ -1,3 +1,3 @@
1
1
  module SandthornDriverSequel
2
- VERSION = "4.0.0"
2
+ VERSION = "4.1.0"
3
3
  end
@@ -10,9 +10,9 @@ module Sandthorn
10
10
  before(:each) { prepare_for_test }
11
11
  let(:test_events_20_events) do
12
12
  e = []
13
- e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}}
13
+ e << {aggregate_version: 1, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {} }
14
14
  19.times do |i|
15
- e << {aggregate_version: i+2, event_name: "foo", event_data: "A2"}
15
+ e << {aggregate_version: i+2, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "foo", event_data: "A2"}
16
16
  end
17
17
  e
18
18
  end
@@ -22,8 +22,8 @@ module Sandthorn
22
22
  end
23
23
  let(:test_events_two_events) do
24
24
  e = []
25
- e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}}
26
- e << {aggregate_version: 2, event_name: "foo", event_data: "A2"}
25
+ e << {aggregate_version: 1, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {} }
26
+ e << {aggregate_version: 2, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "foo", event_data: "A2"}
27
27
  end
28
28
  let(:aggregate_id) {"c0456e26-2345-4f67-92fa-130b3a31a39a"}
29
29
  let(:es) { event_store }
@@ -33,6 +33,11 @@ module SandthornDriverSequel
33
33
  event_name: "foo",
34
34
  event_data: "foo_data",
35
35
  event_metadata: nil
36
+ },{
37
+ aggregate_version: 3,
38
+ event_name: "foo2",
39
+ event_data: "foo_data2",
40
+ event_metadata: nil
36
41
  }
37
42
  ]
38
43
  end
@@ -80,10 +85,37 @@ module SandthornDriverSequel
80
85
  expect(stored_events.size).to eq(events.size)
81
86
  expect(stored_events).to all(respond_to(:merge))
82
87
  end
88
+
89
+ it "returns events in correct order" do
90
+ expect(stored_events.first[:aggregate_version] < stored_events.last[:aggregate_version]).to be_truthy
91
+ expect(stored_events.first[:sequence_number] < stored_events.last[:sequence_number]).to be_truthy
92
+ end
93
+
94
+ end
95
+
96
+ context "when using after_aggregate_version" do
97
+ before do
98
+ access.store_events(aggregate, events)
99
+ end
100
+
101
+ # exclude the first event
102
+ let(:stored_events) { access.find_events_by_aggregate_id(aggregate.aggregate_id, 1) }
103
+
104
+ it "returns correct events" do
105
+ expect(stored_events.map(&:aggregate_table_id)).to all(eq(aggregate.id))
106
+ expect(stored_events.size).to eq(events.size-1)
107
+ expect(stored_events).to all(respond_to(:merge))
108
+ end
109
+
83
110
  it "returns events in correct order" do
84
111
  expect(stored_events.first[:aggregate_version] < stored_events.last[:aggregate_version]).to be_truthy
85
112
  expect(stored_events.first[:sequence_number] < stored_events.last[:sequence_number]).to be_truthy
86
113
  end
114
+
115
+ it "should not return event with aggregate_version = 1" do
116
+ expect(stored_events.first[:aggregate_version]).not_to eq(1)
117
+ end
118
+
87
119
  end
88
120
  end
89
121
 
@@ -8,9 +8,9 @@ module SandthornDriverSequel
8
8
  context("when saving in one context and retrieving in another") do
9
9
  let(:test_events) do
10
10
  e = []
11
- e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}, event_metadata: nil}
12
- e << {aggregate_version: 2, event_name: "foo", event_data: "noop", event_metadata: nil}
13
- e << {aggregate_version: 3, event_name: "flubber", event_data: "noop", event_metadata: nil}
11
+ e << {aggregate_version: 1, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {}, event_metadata: nil}
12
+ e << {aggregate_version: 2, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "foo", event_data: "noop", event_metadata: nil}
13
+ e << {aggregate_version: 3, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "flubber", event_data: "noop", event_metadata: nil}
14
14
  end
15
15
  let(:aggregate_id) {"c0456e26-e29a-4f67-92fa-130b3a31a39b"}
16
16
  it "should not find them" do
@@ -5,25 +5,25 @@ module SandthornDriverSequel
5
5
  before(:each) { prepare_for_test }
6
6
  let(:test_events_a) do
7
7
  e = []
8
- e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}, event_metadata: {a: 1}}
9
- e << {aggregate_version: 2, event_name: "foo", event_data: "A2", event_metadata: {a: 1}}
10
- e << {aggregate_version: 3, event_name: "bard", event_data: "A3", event_metadata: {a: 1}}
8
+ e << {aggregate_version: 1, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {}, event_metadata: {a: 1}}
9
+ e << {aggregate_version: 2, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "foo", event_data: "A2", event_metadata: {a: 1}}
10
+ e << {aggregate_version: 3, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "bard", event_data: "A3", event_metadata: {a: 1}}
11
11
  end
12
12
  let(:aggregate_id_a) {"c0456e26-e29a-4f67-92fa-130b3a31a39a"}
13
13
  let(:test_events_b) do
14
14
  e = []
15
- e << {aggregate_version: 1, event_name: "new", event_data: "B1", event_metadata: 1}
16
- e << {aggregate_version: 2, event_name: "foo", event_data: "B2", event_metadata: 2}
17
- e << {aggregate_version: 3, event_name: "bar", event_data: "B3", event_metadata: 3}
15
+ e << {aggregate_version: 1, aggregate_id: "c0456e26-e29a-4f67-92fa-130b3a31a39a", event_name: "new", event_data: "B1", event_metadata: 1}
16
+ e << {aggregate_version: 2, aggregate_id: "c0456e26-e29a-4f67-92fa-130b3a31a39a", event_name: "foo", event_data: "B2", event_metadata: 2}
17
+ e << {aggregate_version: 3, aggregate_id: "c0456e26-e29a-4f67-92fa-130b3a31a39a", event_name: "bar", event_data: "B3", event_metadata: 3}
18
18
  end
19
19
  let(:aggregate_id_b) {"c0456e26-1234-4f67-92fa-130b3a31a39a"}
20
20
  let(:test_events_c) do
21
21
  e = []
22
- e << {aggregate_version: 1, event_name: "new", event_data: "C1", event_metadata: 4}
22
+ e << {aggregate_version: 1, aggregate_id: "c0456e26-e29a-4f67-92fa-130b3a31a39a", event_name: "new", event_data: "C1", event_metadata: 4}
23
23
  end
24
24
  let(:test_events_c_2) do
25
25
  e = []
26
- e << {aggregate_version: 2, event_name: "flubber", event_data: "C2", event_metadata: 6}
26
+ e << {aggregate_version: 2, aggregate_id: "c0456e26-e29a-4f67-92fa-130b3a31a39a", event_name: "flubber", event_data: "C2", event_metadata: 6}
27
27
  end
28
28
  let(:aggregate_id_c) {"c0456e26-2345-4f67-92fa-130b3a31a39a"}
29
29
  before(:each) do
@@ -6,9 +6,9 @@ module SandthornDriverSequel
6
6
  context "when saving a prefectly sane event stream" do
7
7
  let(:test_events) do
8
8
  e = []
9
- e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}, event_metadata: [1,2,3]}
10
- e << {aggregate_version: 2, event_name: "foo", event_data: "noop", event_metadata: nil}
11
- e << {aggregate_version: 3, event_name: "flubber", event_data: "noop", event_metadata: nil}
9
+ e << {aggregate_version: 1, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {}, event_metadata: [1,2,3]}
10
+ e << {aggregate_version: 2, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "foo", event_data: "noop", event_metadata: nil}
11
+ e << {aggregate_version: 3, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "flubber", event_data: "noop", event_metadata: nil}
12
12
  end
13
13
 
14
14
  let(:aggregate_id) { "c0456e26-e29a-4f67-92fa-130b3a31a39a" }
@@ -28,7 +28,7 @@ module SandthornDriverSequel
28
28
  expect(event[:event_name]).to eql("new")
29
29
  expect(event[:aggregate_id]).to eql aggregate_id
30
30
  expect(event[:aggregate_version]).to eql 1
31
- expect(event[:sequence_number]).to be_a(Fixnum)
31
+ expect(event[:sequence_number]).to be_a(Integer)
32
32
  expect(event[:timestamp]).to be_a(Time)
33
33
  end
34
34
  end
@@ -36,13 +36,13 @@ module SandthornDriverSequel
36
36
  context "when saving two aggregate types" do
37
37
  let(:test_events_1) do
38
38
  e = []
39
- e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}, event_metadata: nil}
40
- e << {aggregate_version: 2, event_name: "foo", event_data: "noop", event_metadata: nil}
41
- e << {aggregate_version: 3, event_name: "flubber", event_data: "noop", event_metadata: nil}
39
+ e << {aggregate_version: 1, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {}, event_metadata: nil}
40
+ e << {aggregate_version: 2, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "foo", event_data: "noop", event_metadata: nil}
41
+ e << {aggregate_version: 3, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "flubber", event_data: "noop", event_metadata: nil}
42
42
  end
43
43
  let(:test_events_2) do
44
44
  e = []
45
- e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}, event_metadata: nil}
45
+ e << {aggregate_version: 1, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {}, event_metadata: nil}
46
46
  end
47
47
  let(:aggregate_id_1) {"c0456e26-e29a-4f67-92fa-130b3a31a39a"}
48
48
  let(:aggregate_id_2) {"c0456e26-e92b-4f67-92fa-130b3a31b93b"}
@@ -65,9 +65,9 @@ module SandthornDriverSequel
65
65
  context "when saving events that have no aggregate_version" do
66
66
  let(:test_events) do
67
67
  e = []
68
- e << {aggregate_version: nil, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>"0a74e545-be84-4506-8b0a-73e947856327"}]}, event_metadata: nil}
69
- e << {aggregate_version: nil, event_name: "foo", event_data: "noop", event_metadata: nil}
70
- e << {aggregate_version: nil, event_name: "flubber", event_data: "noop", event_metadata: nil}
68
+ e << {aggregate_version: nil, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "new", event_data: {}, event_metadata: nil}
69
+ e << {aggregate_version: nil, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "foo", event_data: "noop", event_metadata: nil}
70
+ e << {aggregate_version: nil, aggregate_id: "0a74e545-be84-4506-8b0a-73e947856327", event_name: "flubber", event_data: "noop", event_metadata: nil}
71
71
  end
72
72
 
73
73
  let(:aggregate_id) { "c0456e26-e29a-4f67-92fa-130b3a31a39a" }
@@ -87,7 +87,7 @@ module SandthornDriverSequel
87
87
  expect(event[:event_name]).to eql("new")
88
88
  expect(event[:aggregate_id]).to eql aggregate_id
89
89
  expect(event[:aggregate_version]).to eql 1
90
- expect(event[:sequence_number]).to be_a(Fixnum)
90
+ expect(event[:sequence_number]).to be_a(Integer)
91
91
  expect(event[:timestamp]).to be_a(Time)
92
92
  end
93
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandthorn_driver_sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.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: 2017-05-31 00:00:00.000000000 Z
13
+ date: 2018-06-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -223,7 +223,6 @@ files:
223
223
  - spec/db/.keep
224
224
  - spec/driver_interface_spec.rb
225
225
  - spec/event_access_spec.rb
226
- - spec/event_store_spec.rb
227
226
  - spec/event_store_with_context_spec.rb
228
227
  - spec/get_events_spec.rb
229
228
  - spec/migration_specifying_domain_spec.rb
@@ -250,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
249
  version: '0'
251
250
  requirements: []
252
251
  rubyforge_project:
253
- rubygems_version: 2.4.5.1
252
+ rubygems_version: 2.6.14
254
253
  signing_key:
255
254
  specification_version: 4
256
255
  summary: Sequel driver for Sandthorn
@@ -261,7 +260,6 @@ test_files:
261
260
  - spec/db/.keep
262
261
  - spec/driver_interface_spec.rb
263
262
  - spec/event_access_spec.rb
264
- - spec/event_store_spec.rb
265
263
  - spec/event_store_with_context_spec.rb
266
264
  - spec/get_events_spec.rb
267
265
  - spec/migration_specifying_domain_spec.rb
@@ -1,46 +0,0 @@
1
- # require 'spec_helper'
2
- # module SandthornDriverSequel
3
- # describe EventStore do
4
-
5
- # before(:each) { prepare_for_test context: nil; }
6
- # let(:event_store) { SandthornDriverSequel.driver_from_url url: event_store_url }
7
-
8
- # describe("when getting the same data from find and aggregate_events") do
9
- # let(:test_events) do
10
- # e = []
11
- # e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>aggregate_id}]}, event_meta_data: nil}
12
- # e << {aggregate_version: 2, event_name: "foo", event_data: "noop", event_meta_data: nil}
13
- # e << {aggregate_version: 3, event_name: "flubber", event_data: "noop", event_meta_data: nil}
14
- # end
15
- # let(:aggregate_id) {"c0456e26-e29a-4f67-92fa-130b3a31a39b"}
16
-
17
- # before do
18
- # event_store.save_events test_events, aggregate_id, String
19
- # end
20
-
21
- # context "all" do
22
-
23
- # let(:test_events_2) do
24
- # e = []
25
- # e << {aggregate_version: 1, event_name: "new", event_data: {:attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>aggregate_id_2}]}, event_meta_data: nil}
26
- # e << {aggregate_version: 2, event_name: "foo", event_data: "noop", event_meta_data: nil}
27
- # e << {aggregate_version: 3, event_name: "flubber", event_data: "noop", event_meta_data: nil}
28
- # end
29
- # let(:aggregate_id_2) {"d0456e26-e29a-4f67-92fa-130b3a31a39b"}
30
-
31
- # before do
32
- # event_store.save_events test_events_2, aggregate_id_2, String
33
- # end
34
-
35
- # let(:all_events) do
36
- # event_store.all String
37
- # end
38
-
39
- # it "should get two arrays of events" do
40
- # expect(all_events.length).to eql 2
41
- # end
42
-
43
- # end
44
- # end
45
- # end
46
- # end