rcqrs 0.1.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.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/lib/rcqrs.rb +30 -0
- data/lib/rcqrs/aggregate_root_base.rb +70 -0
- data/lib/rcqrs/base_command.rb +22 -0
- data/lib/rcqrs/base_command_handler.rb +27 -0
- data/lib/rcqrs/base_event.rb +57 -0
- data/lib/rcqrs/command_executor.rb +16 -0
- data/lib/rcqrs/command_not_valid_exception.rb +13 -0
- data/lib/rcqrs/command_source.rb +72 -0
- data/lib/rcqrs/configuration.rb +15 -0
- data/lib/rcqrs/convention_command.rb +32 -0
- data/lib/rcqrs/convention_command_handler.rb +33 -0
- data/lib/rcqrs/denormalizer.rb +79 -0
- data/lib/rcqrs/domain_exception.rb +11 -0
- data/lib/rcqrs/event_bus.rb +59 -0
- data/lib/rcqrs/event_collection.rb +18 -0
- data/lib/rcqrs/event_configuration_base.rb +43 -0
- data/lib/rcqrs/event_handler.rb +55 -0
- data/lib/rcqrs/event_type_registry.rb +16 -0
- data/lib/rcqrs/not_an_event_exception.rb +7 -0
- data/lib/rcqrs/published_event.rb +15 -0
- data/lib/rcqrs/repository.rb +27 -0
- data/lib/rcqrs/unknown_event_exception.rb +3 -0
- data/lib/rcqrs/version.rb +3 -0
- data/rcqrs.gemspec +29 -0
- data/spec/aggregate_root_base_spec.rb +69 -0
- data/spec/base_commandhandler_spec.rb +38 -0
- data/spec/base_event_spec.rb +26 -0
- data/spec/command_executor_spec.rb +12 -0
- data/spec/command_handler_spec.rb +40 -0
- data/spec/configuration_spec.rb +13 -0
- data/spec/convention_command_spec.rb +33 -0
- data/spec/denormalizer_spec.rb +107 -0
- data/spec/eventbus_spec.rb +109 -0
- data/spec/eventhandler_spec.rb +74 -0
- data/spec/repository_spec.rb +75 -0
- data/spec/ricko.rb +181 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/test_aggregate.rb +36 -0
- data/spec/test_command_handler.rb +33 -0
- data/spec/test_command_source.rb +4 -0
- data/spec/test_event.rb +13 -0
- data/spec/test_event_bus.rb +18 -0
- metadata +154 -0
data/spec/ricko.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
module Kernel
|
2
|
+
|
3
|
+
def mockup()
|
4
|
+
Rickomock.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def any expectedType = BasicObject
|
8
|
+
AnyArgumentMatcher.new expectedType
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Rickomock
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@calls = Hash.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(m, *args, &block)
|
19
|
+
if @calls.has_key? m
|
20
|
+
@calls[m].addCall(args)
|
21
|
+
else
|
22
|
+
@calls[m] = MethodCall.new args
|
23
|
+
end
|
24
|
+
if block != nil
|
25
|
+
block.call
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def hasReceivedMessage(method,count,args)
|
30
|
+
if @calls.has_key? method
|
31
|
+
return @calls[method].HasInvocationsWith(count, args)
|
32
|
+
end
|
33
|
+
count == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
def realInvocationMessage
|
37
|
+
if @calls.empty?
|
38
|
+
return "no invocation at all"
|
39
|
+
else
|
40
|
+
result = String.new
|
41
|
+
@calls.each do |methodname, method_call|
|
42
|
+
result << (methodname.to_s + " " + method_call.invocation_message)
|
43
|
+
end
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def message method
|
50
|
+
Verification.new method, self
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class AnyArgumentMatcher
|
55
|
+
|
56
|
+
def initialize expectedType
|
57
|
+
@expectedType = expectedType
|
58
|
+
end
|
59
|
+
|
60
|
+
def ==(other)
|
61
|
+
other.is_a? @expectedType
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
if @expectedType == BasicObject
|
66
|
+
return "any Argument"
|
67
|
+
else
|
68
|
+
return "any Argument of type: " + @expectedType.to_s
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
class Verification
|
75
|
+
def initialize method, mock
|
76
|
+
@method,@mock = method,mock
|
77
|
+
@count = 1
|
78
|
+
end
|
79
|
+
|
80
|
+
def with(*args)
|
81
|
+
@args = args
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
def times(count)
|
86
|
+
@count = count
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
def once
|
91
|
+
times(1)
|
92
|
+
end
|
93
|
+
|
94
|
+
def never
|
95
|
+
times(0)
|
96
|
+
end
|
97
|
+
|
98
|
+
def should_be_received
|
99
|
+
unless @mock.hasReceivedMessage(@method,@count,@args)
|
100
|
+
raise InvocationExpectationError.new buildErrorMessage
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def buildErrorMessage
|
105
|
+
"Expected to receive '" + @method.to_s + "' " + invocationCountMessage + " with " + expectedArguments + " but received " + @mock.realInvocationMessage
|
106
|
+
end
|
107
|
+
|
108
|
+
def invocationCountMessage
|
109
|
+
if @count == 1
|
110
|
+
return "once"
|
111
|
+
end
|
112
|
+
return @count.to_s + " times"
|
113
|
+
end
|
114
|
+
|
115
|
+
def expectedArguments
|
116
|
+
if @args == nil
|
117
|
+
return " no arguments"
|
118
|
+
else
|
119
|
+
result = "("
|
120
|
+
@args.each do |arg|
|
121
|
+
result << (arg.to_s + ":" + arg.class.to_s + ", ")
|
122
|
+
end
|
123
|
+
result = result[0..-3]
|
124
|
+
result << ")"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
class MethodCall
|
131
|
+
|
132
|
+
def initialize arguments
|
133
|
+
@callCount = 1
|
134
|
+
@args = [arguments]
|
135
|
+
end
|
136
|
+
|
137
|
+
def addCall arguments
|
138
|
+
@callCount += 1
|
139
|
+
@args << arguments
|
140
|
+
end
|
141
|
+
|
142
|
+
def HasInvocationsWith(count,args)
|
143
|
+
has = @callCount == count
|
144
|
+
if args != nil
|
145
|
+
@args.each do |arguments|
|
146
|
+
has &= checkArgs(args,arguments)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
has
|
150
|
+
end
|
151
|
+
|
152
|
+
def checkArgs(expectedArguments,actualArguments)
|
153
|
+
if(expectedArguments.length != actualArguments.length)
|
154
|
+
return false
|
155
|
+
end
|
156
|
+
sameArguments = true
|
157
|
+
expectedArguments.length.times do |i|
|
158
|
+
sameArguments &= (expectedArguments[i] == actualArguments[i])
|
159
|
+
end
|
160
|
+
sameArguments
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def invocation_message
|
165
|
+
result = "called " + @callCount.to_s + " with arguments: "
|
166
|
+
@args.each do |arguments|
|
167
|
+
result << "("
|
168
|
+
arguments.each do |arg|
|
169
|
+
result << (arg.to_s + ":" + arg.class.to_s + ", ")
|
170
|
+
end
|
171
|
+
result = result[0..-3]
|
172
|
+
result << ")"
|
173
|
+
end
|
174
|
+
result
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class InvocationExpectationError < StandardError
|
179
|
+
|
180
|
+
end
|
181
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require "rspec-spies"
|
9
|
+
|
10
|
+
require_relative "../lib/rcqrs"
|
11
|
+
|
12
|
+
require_relative "test_aggregate"
|
13
|
+
require_relative "test_event"
|
14
|
+
require_relative "test_command_handler"
|
15
|
+
require_relative "ricko"
|
16
|
+
require_relative "test_command_source"
|
17
|
+
require_relative "test_event_bus"
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
21
|
+
config.run_all_when_everything_filtered = true
|
22
|
+
config.filter_run :focus
|
23
|
+
|
24
|
+
# Run specs in random order to surface order dependencies. If you find an
|
25
|
+
# order dependency and want to debug it, you can fix the order by providing
|
26
|
+
# the seed, which is printed after each run.
|
27
|
+
# --seed 1234
|
28
|
+
config.order = 'random'
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module TestAggregateModule
|
2
|
+
|
3
|
+
class TestAggregate < Rcqrs::AggregateRootBase
|
4
|
+
|
5
|
+
attr_reader :handledEvents
|
6
|
+
|
7
|
+
def initialize id
|
8
|
+
super
|
9
|
+
@handledEvents = Array.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def doSomething
|
13
|
+
fire TestEventModule::TestEvent.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def do_something_else
|
17
|
+
fire TestEventModule::AnotherTestEvent.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def doSomethingStupid
|
21
|
+
fire "no Event"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def handleTestEvent event
|
27
|
+
@handledEvents << event
|
28
|
+
end
|
29
|
+
|
30
|
+
handle :AnotherTestEvent do |event|
|
31
|
+
@handledEvents << event
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class TestCommand
|
2
|
+
attr_accessor :param
|
3
|
+
|
4
|
+
def initialize param
|
5
|
+
@param = param
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class NonExistingCommand
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestCommandHandler < Rcqrs::BaseCommandHandler
|
14
|
+
|
15
|
+
def self.repository
|
16
|
+
@@repository
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.was_called_with
|
20
|
+
@@was_called_with
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute command
|
24
|
+
@@was_called_with = command.param
|
25
|
+
@@repository = repository
|
26
|
+
@execute_called = true
|
27
|
+
end
|
28
|
+
|
29
|
+
def execute_called?
|
30
|
+
@execute_called
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/test_event.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class TestEventBus
|
2
|
+
|
3
|
+
def self.transaction_executed
|
4
|
+
@@transaction_executed
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.commit
|
8
|
+
@@transaction_executed = true
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.publish(aggregate_id, event)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load_events(aggregate_id)
|
15
|
+
Array.new
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rcqrs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tim de Putter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70200857308760 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70200857308760
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec-spies
|
27
|
+
requirement: &70200857308340 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70200857308340
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activemodel
|
38
|
+
requirement: &70200857307920 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70200857307920
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: uuid
|
49
|
+
requirement: &70200857307480 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70200857307480
|
58
|
+
description: Framework to provide cqrs + eventsourcing functionality in ruby.
|
59
|
+
email:
|
60
|
+
- tim.de.putter83@googlemail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/rcqrs.rb
|
71
|
+
- lib/rcqrs/aggregate_root_base.rb
|
72
|
+
- lib/rcqrs/base_command.rb
|
73
|
+
- lib/rcqrs/base_command_handler.rb
|
74
|
+
- lib/rcqrs/base_event.rb
|
75
|
+
- lib/rcqrs/command_executor.rb
|
76
|
+
- lib/rcqrs/command_not_valid_exception.rb
|
77
|
+
- lib/rcqrs/command_source.rb
|
78
|
+
- lib/rcqrs/configuration.rb
|
79
|
+
- lib/rcqrs/convention_command.rb
|
80
|
+
- lib/rcqrs/convention_command_handler.rb
|
81
|
+
- lib/rcqrs/denormalizer.rb
|
82
|
+
- lib/rcqrs/domain_exception.rb
|
83
|
+
- lib/rcqrs/event_bus.rb
|
84
|
+
- lib/rcqrs/event_collection.rb
|
85
|
+
- lib/rcqrs/event_configuration_base.rb
|
86
|
+
- lib/rcqrs/event_handler.rb
|
87
|
+
- lib/rcqrs/event_type_registry.rb
|
88
|
+
- lib/rcqrs/not_an_event_exception.rb
|
89
|
+
- lib/rcqrs/published_event.rb
|
90
|
+
- lib/rcqrs/repository.rb
|
91
|
+
- lib/rcqrs/unknown_event_exception.rb
|
92
|
+
- lib/rcqrs/version.rb
|
93
|
+
- rcqrs.gemspec
|
94
|
+
- spec/aggregate_root_base_spec.rb
|
95
|
+
- spec/base_commandhandler_spec.rb
|
96
|
+
- spec/base_event_spec.rb
|
97
|
+
- spec/command_executor_spec.rb
|
98
|
+
- spec/command_handler_spec.rb
|
99
|
+
- spec/configuration_spec.rb
|
100
|
+
- spec/convention_command_spec.rb
|
101
|
+
- spec/denormalizer_spec.rb
|
102
|
+
- spec/eventbus_spec.rb
|
103
|
+
- spec/eventhandler_spec.rb
|
104
|
+
- spec/repository_spec.rb
|
105
|
+
- spec/ricko.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/test_aggregate.rb
|
108
|
+
- spec/test_command_handler.rb
|
109
|
+
- spec/test_command_source.rb
|
110
|
+
- spec/test_event.rb
|
111
|
+
- spec/test_event_bus.rb
|
112
|
+
homepage:
|
113
|
+
licenses: []
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project: rcqrs
|
132
|
+
rubygems_version: 1.8.10
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: Framework to provide cqrs + eventsourcing functionality in ruby.
|
136
|
+
test_files:
|
137
|
+
- spec/aggregate_root_base_spec.rb
|
138
|
+
- spec/base_commandhandler_spec.rb
|
139
|
+
- spec/base_event_spec.rb
|
140
|
+
- spec/command_executor_spec.rb
|
141
|
+
- spec/command_handler_spec.rb
|
142
|
+
- spec/configuration_spec.rb
|
143
|
+
- spec/convention_command_spec.rb
|
144
|
+
- spec/denormalizer_spec.rb
|
145
|
+
- spec/eventbus_spec.rb
|
146
|
+
- spec/eventhandler_spec.rb
|
147
|
+
- spec/repository_spec.rb
|
148
|
+
- spec/ricko.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/test_aggregate.rb
|
151
|
+
- spec/test_command_handler.rb
|
152
|
+
- spec/test_command_source.rb
|
153
|
+
- spec/test_event.rb
|
154
|
+
- spec/test_event_bus.rb
|