event_sourcing 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +7 -0
  5. data/Guardfile +12 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +13 -0
  9. data/event_sourcing.gemspec +28 -0
  10. data/features/steps/whole_stack.rb +29 -0
  11. data/features/support/env.rb +5 -0
  12. data/features/support/logger.log +1 -0
  13. data/features/support/sample_app.rb +40 -0
  14. data/features/support/spinach.log +0 -0
  15. data/features/whole_stack.feature +6 -0
  16. data/lib/event_sourcing.rb +3 -0
  17. data/lib/event_sourcing/aggregate.rb +30 -0
  18. data/lib/event_sourcing/aggregate/actor.rb +29 -0
  19. data/lib/event_sourcing/aggregate/manager.rb +33 -0
  20. data/lib/event_sourcing/aggregate/manager/cache.rb +17 -0
  21. data/lib/event_sourcing/aggregate/manager/instance_of.rb +11 -0
  22. data/lib/event_sourcing/aggregate/manager/reference.rb +14 -0
  23. data/lib/event_sourcing/aggregate/message.rb +7 -0
  24. data/lib/event_sourcing/aggregate/wrapper.rb +18 -0
  25. data/lib/event_sourcing/application.rb +37 -0
  26. data/lib/event_sourcing/application/actor.rb +40 -0
  27. data/lib/event_sourcing/application/actor/reference.rb +23 -0
  28. data/lib/event_sourcing/command.rb +30 -0
  29. data/lib/event_sourcing/command/bus.rb +16 -0
  30. data/lib/event_sourcing/event.rb +29 -0
  31. data/lib/event_sourcing/event/bus.rb +29 -0
  32. data/lib/event_sourcing/event/bus/reference.rb +28 -0
  33. data/lib/event_sourcing/event/publisher.rb +47 -0
  34. data/lib/event_sourcing/event/publisher/reference.rb +11 -0
  35. data/lib/event_sourcing/event/store.rb +8 -0
  36. data/lib/event_sourcing/event/store/memory.rb +43 -0
  37. data/lib/event_sourcing/event/stream.rb +23 -0
  38. data/lib/event_sourcing/event/subscriber.rb +16 -0
  39. data/lib/event_sourcing/version.rb +3 -0
  40. data/spec/concurrent_logging.rb +6 -0
  41. data/spec/spec_helper.rb +8 -0
  42. data/spec/support/actor_helpers.rb +11 -0
  43. data/spec/support/shared_examples/a_store_implementation.rb +70 -0
  44. data/spec/unit/aggregate/actor_spec.rb +59 -0
  45. data/spec/unit/aggregate/manager/cache_spec.rb +26 -0
  46. data/spec/unit/aggregate/manager/reference_spec.rb +14 -0
  47. data/spec/unit/aggregate/manager_spec.rb +32 -0
  48. data/spec/unit/aggregate/wrapper_spec.rb +22 -0
  49. data/spec/unit/aggregate_spec.rb +75 -0
  50. data/spec/unit/application/actor/reference_spec.rb +25 -0
  51. data/spec/unit/application/actor_spec.rb +36 -0
  52. data/spec/unit/application_spec.rb +41 -0
  53. data/spec/unit/command/bus_spec.rb +15 -0
  54. data/spec/unit/command_spec.rb +38 -0
  55. data/spec/unit/event/bus/reference_spec.rb +48 -0
  56. data/spec/unit/event/bus_spec.rb +41 -0
  57. data/spec/unit/event/publisher_spec.rb +28 -0
  58. data/spec/unit/event/store/memory_spec.rb +6 -0
  59. data/spec/unit/event/stream_spec.rb +30 -0
  60. data/spec/unit/event/subscriber_spec.rb +27 -0
  61. data/spec/unit/event_spec.rb +27 -0
  62. data/spec/unit_helper.rb +14 -0
  63. metadata +233 -0
@@ -0,0 +1,41 @@
1
+ require "unit_helper"
2
+ require "event_sourcing/event/bus"
3
+
4
+ describe EventSourcing::Event::Bus do
5
+ let(:bus) { EventSourcing::Event::Bus.new(event_store) }
6
+ let(:event_store) { instance_double("EventSourcing::Event::Store::Memory") }
7
+
8
+ it "is a RestartingContext" do
9
+ expect(EventSourcing::Event::Bus < Concurrent::Actor::RestartingContext).to be_truthy
10
+ end
11
+
12
+ it "uses a custom Reference class" do
13
+ expect(bus.default_reference_class).to eq(EventSourcing::Event::Bus::Reference)
14
+ end
15
+
16
+ context "when sent a :get_event_store message" do
17
+ it "returns the event store" do
18
+ expect(bus.on_message(:get_event_store)).to eq(event_store)
19
+ end
20
+ end
21
+
22
+ context "when sent a :get_event_publisher message" do
23
+
24
+ let(:publisher_class) { class_double("EventSourcing::Event::Publisher").as_stubbed_const }
25
+ let(:publisher) { double("Publisher ref") }
26
+
27
+ subject { bus.on_message(:get_event_publisher) }
28
+
29
+ before do
30
+ allow(publisher_class).to receive(:spawn!).once.with(name: :event_publisher, supervise: true).and_return(publisher)
31
+ end
32
+
33
+ it "returns a supervised event publisher" do
34
+ expect(subject).to eq(publisher)
35
+ end
36
+
37
+ it "memoizes the reference" do
38
+ expect(subject).to eq(bus.on_message(:get_event_publisher))
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ require "unit_helper"
2
+ require "event_sourcing/event/publisher"
3
+
4
+ describe EventSourcing::Event::Publisher do
5
+ context "subscribe" do
6
+ SomeEvent = EventSourcing::Event.define
7
+ AnotherEvent = EventSourcing::Event.define
8
+ let(:publisher) { EventSourcing::Event::Publisher.new }
9
+ let(:event) { SomeEvent.new }
10
+ let(:another_event) { AnotherEvent.new }
11
+ let(:subscriber) { double("subscriber class", to_s: "SubscriberClass") }
12
+ let(:subscriber_actor) { double("Subscriber actor") }
13
+
14
+ before do
15
+ EventSourcing::Event::Publisher.subscribe(subscriber, event)
16
+ EventSourcing::Event::Publisher.subscribe(subscriber, another_event)
17
+ allow(subscriber).to receive(:spawn!).once.with(name: "SubscriberClass", supervise: true).and_return(subscriber_actor)
18
+ end
19
+
20
+ after do
21
+ publisher.on_message(event)
22
+ end
23
+
24
+ it "publishes events to subscribers" do
25
+ expect(subscriber_actor).to receive(:tell).with(event)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+ require "event_sourcing/event/store/memory"
3
+
4
+ describe EventSourcing::Event::Store::Memory do
5
+ it_behaves_like "a store implementation"
6
+ end
@@ -0,0 +1,30 @@
1
+ require "unit_helper"
2
+ require "event_sourcing/event/stream"
3
+
4
+ describe EventSourcing::Event::Stream do
5
+
6
+ subject { stream }
7
+ let(:stream) { EventSourcing::Event::Stream.new("some-id", events, version, store) }
8
+ let(:events) { [double("Event")] }
9
+ let(:version) { 1 }
10
+ let(:store) { instance_double("EventSourcing::Event::Store::Memory") }
11
+
12
+ it "is a enumerable list of events" do
13
+ expect(subject.first).to eq(events.first)
14
+ end
15
+
16
+ it "has a version" do
17
+ expect(subject.version).to eq(version)
18
+ end
19
+
20
+ context "push" do
21
+ after do
22
+ stream.append(events)
23
+ end
24
+
25
+ it "pushes events into the event store" do
26
+ expect(store).to receive(:append).with("some-id", version, events)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ require "unit_helper"
2
+ require "event_sourcing/event/subscriber"
3
+
4
+ describe EventSourcing::Event::Subscriber do
5
+ let(:subscriber) do
6
+ Class.new(EventSourcing::Event::Subscriber) do
7
+ subscribe_to "SomeEvent" do |event|
8
+ "received #{event}!"
9
+ end
10
+ end
11
+ end
12
+
13
+ let(:publisher) { class_double("EventSourcing::Event::Publisher").as_stubbed_const }
14
+ let(:event) { event_double("SomeEvent") }
15
+
16
+ before do
17
+ allow(publisher).to receive(:subscribe)
18
+ end
19
+
20
+ it "adds the subscriber to the list of subscribers" do
21
+ expect(publisher).to have_received(:subscribe).with(subscriber, "SomeEvent")
22
+ end
23
+
24
+ it "adds an event handler" do
25
+ expect(subscriber.new.on_message(event)).to eq("received SomeEvent!")
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require "unit_helper"
2
+ require "event_sourcing/event"
3
+
4
+ describe EventSourcing::Event do
5
+
6
+ it "can't be directly instantiated" do
7
+ expect { EventSourcing::Event.new }.to raise_error(NoMethodError)
8
+ end
9
+
10
+ context "defined with required parameters" do
11
+ subject { EventSourcing::Event.define(:required_param) }
12
+
13
+ it "raises an error when those are not provided" do
14
+ expect { subject.new }.to raise_error(ArgumentError, "missing keyword: required_param")
15
+ end
16
+
17
+ it "has setters" do
18
+ expect(subject.new(required_param: "some value").required_param).to eq("some value")
19
+ end
20
+ end
21
+
22
+ context "defined" do
23
+ it "are a kind of EventSourcing::Event" do
24
+ expect(EventSourcing::Event.define.new).to be_a(EventSourcing::Event)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require "rspec"
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:all) do
5
+ require_relative "concurrent_logging" if RSpec.configuration.full_backtrace?
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_doubled_constant_names = false
10
+ mocks.verify_partial_doubles = false
11
+ end
12
+ end
13
+
14
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f}
metadata ADDED
@@ -0,0 +1,233 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: event_sourcing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Alvarez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: values
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.6'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: spinach
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-spinach
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ prerelease: false
110
+ type: :development
111
+ description:
112
+ email:
113
+ - papipo@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - Gemfile
121
+ - Guardfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - event_sourcing.gemspec
126
+ - features/steps/whole_stack.rb
127
+ - features/support/env.rb
128
+ - features/support/logger.log
129
+ - features/support/sample_app.rb
130
+ - features/support/spinach.log
131
+ - features/whole_stack.feature
132
+ - lib/event_sourcing.rb
133
+ - lib/event_sourcing/aggregate.rb
134
+ - lib/event_sourcing/aggregate/actor.rb
135
+ - lib/event_sourcing/aggregate/manager.rb
136
+ - lib/event_sourcing/aggregate/manager/cache.rb
137
+ - lib/event_sourcing/aggregate/manager/instance_of.rb
138
+ - lib/event_sourcing/aggregate/manager/reference.rb
139
+ - lib/event_sourcing/aggregate/message.rb
140
+ - lib/event_sourcing/aggregate/wrapper.rb
141
+ - lib/event_sourcing/application.rb
142
+ - lib/event_sourcing/application/actor.rb
143
+ - lib/event_sourcing/application/actor/reference.rb
144
+ - lib/event_sourcing/command.rb
145
+ - lib/event_sourcing/command/bus.rb
146
+ - lib/event_sourcing/event.rb
147
+ - lib/event_sourcing/event/bus.rb
148
+ - lib/event_sourcing/event/bus/reference.rb
149
+ - lib/event_sourcing/event/publisher.rb
150
+ - lib/event_sourcing/event/publisher/reference.rb
151
+ - lib/event_sourcing/event/store.rb
152
+ - lib/event_sourcing/event/store/memory.rb
153
+ - lib/event_sourcing/event/stream.rb
154
+ - lib/event_sourcing/event/subscriber.rb
155
+ - lib/event_sourcing/version.rb
156
+ - spec/concurrent_logging.rb
157
+ - spec/spec_helper.rb
158
+ - spec/support/actor_helpers.rb
159
+ - spec/support/shared_examples/a_store_implementation.rb
160
+ - spec/unit/aggregate/actor_spec.rb
161
+ - spec/unit/aggregate/manager/cache_spec.rb
162
+ - spec/unit/aggregate/manager/reference_spec.rb
163
+ - spec/unit/aggregate/manager_spec.rb
164
+ - spec/unit/aggregate/wrapper_spec.rb
165
+ - spec/unit/aggregate_spec.rb
166
+ - spec/unit/application/actor/reference_spec.rb
167
+ - spec/unit/application/actor_spec.rb
168
+ - spec/unit/application_spec.rb
169
+ - spec/unit/command/bus_spec.rb
170
+ - spec/unit/command_spec.rb
171
+ - spec/unit/event/bus/reference_spec.rb
172
+ - spec/unit/event/bus_spec.rb
173
+ - spec/unit/event/publisher_spec.rb
174
+ - spec/unit/event/store/memory_spec.rb
175
+ - spec/unit/event/stream_spec.rb
176
+ - spec/unit/event/subscriber_spec.rb
177
+ - spec/unit/event_spec.rb
178
+ - spec/unit_helper.rb
179
+ homepage: https://github.com/Papipo/event_sourcing
180
+ licenses:
181
+ - MIT
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.2.2
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: Actor based EventSourcing framework for ruby.
203
+ test_files:
204
+ - features/steps/whole_stack.rb
205
+ - features/support/env.rb
206
+ - features/support/logger.log
207
+ - features/support/sample_app.rb
208
+ - features/support/spinach.log
209
+ - features/whole_stack.feature
210
+ - spec/concurrent_logging.rb
211
+ - spec/spec_helper.rb
212
+ - spec/support/actor_helpers.rb
213
+ - spec/support/shared_examples/a_store_implementation.rb
214
+ - spec/unit/aggregate/actor_spec.rb
215
+ - spec/unit/aggregate/manager/cache_spec.rb
216
+ - spec/unit/aggregate/manager/reference_spec.rb
217
+ - spec/unit/aggregate/manager_spec.rb
218
+ - spec/unit/aggregate/wrapper_spec.rb
219
+ - spec/unit/aggregate_spec.rb
220
+ - spec/unit/application/actor/reference_spec.rb
221
+ - spec/unit/application/actor_spec.rb
222
+ - spec/unit/application_spec.rb
223
+ - spec/unit/command/bus_spec.rb
224
+ - spec/unit/command_spec.rb
225
+ - spec/unit/event/bus/reference_spec.rb
226
+ - spec/unit/event/bus_spec.rb
227
+ - spec/unit/event/publisher_spec.rb
228
+ - spec/unit/event/store/memory_spec.rb
229
+ - spec/unit/event/stream_spec.rb
230
+ - spec/unit/event/subscriber_spec.rb
231
+ - spec/unit/event_spec.rb
232
+ - spec/unit_helper.rb
233
+ has_rdoc: