rohbau 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/lib/rohbau/failure.rb +12 -0
- data/lib/rohbau/success.rb +12 -0
- data/lib/rohbau/version.rb +1 -1
- data/spec/failure_spec.rb +22 -0
- data/spec/success_spec.rb +22 -0
- data/spec/unit/rohbau/entity_spec.rb +106 -0
- data/spec/unit/rohbau/index_spec.rb +332 -6
- metadata +10 -3
- data/lib/rohbau/shared_specs/default_gateway.rb +0 -301
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 589d8a1f649094a7a7f76534dcbda6495e41bc3f
|
|
4
|
+
data.tar.gz: 97ea6decb78ab17122f24afefda6f552ac2b114a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 106a58c5e4d7ece5c30f470917b86654eefb1c400326f5b45bd7ce2f5a12742af0e87a4e79d334673204427e87d711608e33d2bf015cd3e1d19c37aabd5e83eb
|
|
7
|
+
data.tar.gz: dfd94bdadbf507cdc1d1b5397a427b7bff23d3feed9face5b4b4963924705a9c260619b9b1847151786078344f780376163a686892f96725df9f727d18a71415
|
data/lib/rohbau/version.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rohbau/failure'
|
|
3
|
+
|
|
4
|
+
describe Rohbau::Failure do
|
|
5
|
+
let(:subject) { Rohbau::Failure.new }
|
|
6
|
+
|
|
7
|
+
it 'inherits from Bound' do
|
|
8
|
+
assert_includes subject.ancestors, Bound::StaticBoundClass
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'is a failure' do
|
|
12
|
+
assert_equal true, subject.failure?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'is no success' do
|
|
16
|
+
assert_equal false, subject.success?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'it does not polute Class' do
|
|
20
|
+
refute_includes Class.instance_methods, :failure?
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rohbau/success'
|
|
3
|
+
|
|
4
|
+
describe Rohbau::Success do
|
|
5
|
+
let(:subject) { Rohbau::Success.new }
|
|
6
|
+
|
|
7
|
+
it 'inherits from Bound' do
|
|
8
|
+
assert_includes subject.ancestors, Bound::StaticBoundClass
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'is a success' do
|
|
12
|
+
assert_equal true, subject.success?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'is no failure' do
|
|
16
|
+
assert_equal false, subject.failure?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'it does not polute Class' do
|
|
20
|
+
refute_includes Class.instance_methods, :success?
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'rohbau/entity'
|
|
3
|
+
|
|
4
|
+
describe Rohbau::Entity do
|
|
5
|
+
describe 'class' do
|
|
6
|
+
let(:entity_class) { Rohbau::Entity }
|
|
7
|
+
|
|
8
|
+
it 'accepts list of attributes' do
|
|
9
|
+
entity_class.attributes(:city, :country)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'initializes' do
|
|
13
|
+
assert entity_class.new.is_a?(Rohbau::Entity)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe 'instance' do
|
|
18
|
+
let(:entity) { Person.new }
|
|
19
|
+
|
|
20
|
+
it 'provides accessor' do
|
|
21
|
+
assert_equal nil, entity.name
|
|
22
|
+
|
|
23
|
+
entity.name = 'fasel'
|
|
24
|
+
|
|
25
|
+
assert_equal 'fasel', entity.name
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'predicate attribute' do
|
|
29
|
+
it 'should be false without value' do
|
|
30
|
+
assert_equal false, entity.name?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should be false with false as value' do
|
|
34
|
+
entity.name = false
|
|
35
|
+
|
|
36
|
+
assert_equal false, entity.name?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should be true with value' do
|
|
40
|
+
entity.name = 'fasel'
|
|
41
|
+
|
|
42
|
+
assert_equal true, entity.name?
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe 'equality' do
|
|
47
|
+
let(:person_1) { Person.new }
|
|
48
|
+
let(:person_2) { Person.new }
|
|
49
|
+
let(:dog) { Dog.new }
|
|
50
|
+
let(:cat) { Cat.new }
|
|
51
|
+
|
|
52
|
+
it 'is equal with identical entity class' do
|
|
53
|
+
[person_1, person_2].each do |entity|
|
|
54
|
+
entity.name = 'Johnny'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
assert person_1 == person_2
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'is equal with different entity classes' do
|
|
61
|
+
[person_1, dog].each do |entity|
|
|
62
|
+
entity.name = 'Johnny'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
assert person_1 == dog
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'is equal with additional attribute' do
|
|
69
|
+
[dog, cat].each do |entity|
|
|
70
|
+
entity.name = 'Johnny'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
assert dog == cat
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'is not equal with missing attribute' do
|
|
77
|
+
[dog, cat].each do |entity|
|
|
78
|
+
entity.name = 'Johnny'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
refute cat == dog
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'is not equal with different attributes' do
|
|
85
|
+
person_1.name = 'Johnny'
|
|
86
|
+
person_2.name = 'Brad'
|
|
87
|
+
|
|
88
|
+
refute person_1 == person_2
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
class Person < Rohbau::Entity
|
|
96
|
+
attributes :name, :name?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class Dog < Rohbau::Entity
|
|
100
|
+
attributes :name, :name?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
class Cat < Rohbau::Entity
|
|
104
|
+
attributes :name, :name?, :color
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -1,17 +1,343 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'rohbau/index'
|
|
3
|
+
require 'rohbau/entity'
|
|
3
4
|
|
|
4
5
|
describe Rohbau::Index do
|
|
5
6
|
let(:index) { Rohbau::Index.new }
|
|
7
|
+
let(:entity) { Entity.new }
|
|
6
8
|
|
|
7
|
-
describe '
|
|
8
|
-
it '
|
|
9
|
-
|
|
9
|
+
describe 'default options' do
|
|
10
|
+
it 'enables uid_generation' do
|
|
11
|
+
assert index.option?(:uid_generation)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
it '
|
|
13
|
-
|
|
14
|
-
assert_equal
|
|
14
|
+
it 'assigns DefaultMapper as mapper' do
|
|
15
|
+
assert index.option?(:mapper)
|
|
16
|
+
assert_equal Rohbau::Index::DefaultMapper, index.option(:mapper)
|
|
15
17
|
end
|
|
18
|
+
|
|
19
|
+
it 'assigns DefaultMapper as unmapper' do
|
|
20
|
+
assert index.option?(:unmapper)
|
|
21
|
+
assert_equal Rohbau::Index::DefaultMapper, index.option(:unmapper)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'setting options' do
|
|
26
|
+
it 'disables uid_generation' do
|
|
27
|
+
index.option(:uid_generation, false)
|
|
28
|
+
|
|
29
|
+
refute index.option?(:uid_generation)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'assigns OwnMapper as mapper' do
|
|
33
|
+
index.option(:mapper, OwnMapper)
|
|
34
|
+
|
|
35
|
+
assert_equal OwnMapper, index.option(:mapper)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'assigns OwnMapper as unmapper' do
|
|
39
|
+
index.option(:unmapper, OwnMapper)
|
|
40
|
+
|
|
41
|
+
assert_equal OwnMapper, index.option(:unmapper)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe 'size' do
|
|
46
|
+
describe 'empty' do
|
|
47
|
+
it 'has size 0' do
|
|
48
|
+
assert_equal 0, index.size
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe 'with entities' do
|
|
53
|
+
before do
|
|
54
|
+
index.add(entity)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'has size 1' do
|
|
58
|
+
assert_equal 1, index.size
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe 'each' do
|
|
64
|
+
describe 'empty' do
|
|
65
|
+
it 'yields nothing' do
|
|
66
|
+
a = 0
|
|
67
|
+
index.each do
|
|
68
|
+
a += 1
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
assert_equal 0, a
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe 'with entities' do
|
|
76
|
+
before do
|
|
77
|
+
index.add(entity)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'yields block for every entity' do
|
|
81
|
+
a = 0
|
|
82
|
+
index.each do
|
|
83
|
+
a += 1
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
assert_equal 1, a
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe 'all' do
|
|
92
|
+
describe 'empty' do
|
|
93
|
+
it 'does not contain any entities' do
|
|
94
|
+
assert_equal [], index.all
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe 'with entities' do
|
|
99
|
+
it 'returns all entities' do
|
|
100
|
+
added_entity = index.add(entity)
|
|
101
|
+
|
|
102
|
+
assert_equal [added_entity], index.all
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
describe 'add' do
|
|
108
|
+
describe 'without uid' do
|
|
109
|
+
it 'generates a uid' do
|
|
110
|
+
refute entity.uid
|
|
111
|
+
|
|
112
|
+
added_entity = index.add(entity)
|
|
113
|
+
|
|
114
|
+
assert_equal '1', added_entity.uid
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'is present in collection' do
|
|
118
|
+
added_entity = index.add(entity)
|
|
119
|
+
|
|
120
|
+
assert_equal added_entity, index.all[0]
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe 'with uid' do
|
|
125
|
+
it 'should fail' do
|
|
126
|
+
entity.uid = '1'
|
|
127
|
+
|
|
128
|
+
error = assert_raises(ArgumentError) do
|
|
129
|
+
index.add(entity)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
assert_match Regexp.new('entity has uid'), error.message
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe 'without entity' do
|
|
137
|
+
it 'should fail' do
|
|
138
|
+
error = assert_raises(ArgumentError) do
|
|
139
|
+
index.add(nil)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
assert_match Regexp.new('entity is invalid'), error.message
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe 'without uid_generation' do
|
|
147
|
+
let(:uid) { '1' }
|
|
148
|
+
|
|
149
|
+
before do
|
|
150
|
+
index.option(:uid_generation, false)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe 'with uid' do
|
|
154
|
+
before do
|
|
155
|
+
entity.uid = uid
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'keeps the uid' do
|
|
159
|
+
added_entity = index.add(entity)
|
|
160
|
+
|
|
161
|
+
assert_equal uid, added_entity.uid
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'is present in collection' do
|
|
165
|
+
added_entity = index.add(entity)
|
|
166
|
+
|
|
167
|
+
assert_equal added_entity, index.all[0]
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
describe 'without uid' do
|
|
172
|
+
it 'should fail' do
|
|
173
|
+
error = assert_raises(ArgumentError) do
|
|
174
|
+
index.add(entity)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
assert_match Regexp.new('entity has no uid'), error.message
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
describe 'with invalid uid' do
|
|
182
|
+
it 'should fail' do
|
|
183
|
+
['', 1].each do |invalid_uid|
|
|
184
|
+
entity.uid = invalid_uid
|
|
185
|
+
|
|
186
|
+
error = assert_raises(ArgumentError) do
|
|
187
|
+
index.add(entity)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
assert_match Regexp.new('uid is invalid'), error.message
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe 'bulk_add' do
|
|
197
|
+
let(:entities) { [entity, entity] }
|
|
198
|
+
|
|
199
|
+
it 'adds multiple entities' do
|
|
200
|
+
added_entities = index.bulk_add(entities)
|
|
201
|
+
|
|
202
|
+
assert_equal added_entities, index.all
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
describe 'get' do
|
|
207
|
+
let(:entities) { [entity, entity] }
|
|
208
|
+
|
|
209
|
+
it 'gets entity by uid' do
|
|
210
|
+
added_entity = index.add(entity)
|
|
211
|
+
|
|
212
|
+
assert_equal added_entity, index.get(added_entity.uid)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
describe 'without uid' do
|
|
216
|
+
it 'should fail' do
|
|
217
|
+
error = assert_raises(ArgumentError) do
|
|
218
|
+
index.get(nil)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
assert_match Regexp.new('uid is missing'), error.message
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
describe 'with invalid uid' do
|
|
226
|
+
it 'should fail' do
|
|
227
|
+
['', 1].each do |invalid_uid|
|
|
228
|
+
entity.uid = invalid_uid
|
|
229
|
+
|
|
230
|
+
error = assert_raises(ArgumentError) do
|
|
231
|
+
index.get(entity.uid)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
assert_match Regexp.new('uid is invalid'), error.message
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
describe 'update' do
|
|
241
|
+
it 'succeeds' do
|
|
242
|
+
added_entity = index.add(entity)
|
|
243
|
+
|
|
244
|
+
refute added_entity.name
|
|
245
|
+
|
|
246
|
+
added_entity.name = 'foo'
|
|
247
|
+
updated_entity = index.update(added_entity)
|
|
248
|
+
|
|
249
|
+
assert_equal 'foo', updated_entity.name
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
describe 'without uid' do
|
|
253
|
+
it 'should fail' do
|
|
254
|
+
error = assert_raises(ArgumentError) do
|
|
255
|
+
index.update(entity)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
assert_match Regexp.new('entity has no uid'), error.message
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
describe 'without entity' do
|
|
263
|
+
it 'should fail' do
|
|
264
|
+
error = assert_raises(ArgumentError) do
|
|
265
|
+
index.update(nil)
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
assert_match Regexp.new('entity is invalid'), error.message
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
describe 'with unknown entity' do
|
|
273
|
+
it 'should fail' do
|
|
274
|
+
entity.uid = 'unknown'
|
|
275
|
+
|
|
276
|
+
error = assert_raises(ArgumentError) do
|
|
277
|
+
index.update(entity)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
assert_match Regexp.new('entity is unknown'), error.message
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
describe 'delete' do
|
|
286
|
+
it 'removes entity' do
|
|
287
|
+
added_entity = index.add(entity)
|
|
288
|
+
|
|
289
|
+
assert index.get(added_entity.uid)
|
|
290
|
+
index.delete(added_entity.uid)
|
|
291
|
+
|
|
292
|
+
refute index.get(added_entity.uid)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
describe 'with unknown uid' do
|
|
296
|
+
it 'should fail' do
|
|
297
|
+
uid = 'unknown'
|
|
298
|
+
|
|
299
|
+
error = assert_raises(ArgumentError) do
|
|
300
|
+
index.delete(uid)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
assert_match Regexp.new('uid is unknown'), error.message
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
describe 'bulk_delete' do
|
|
309
|
+
let(:entities) { [entity, entity] }
|
|
310
|
+
|
|
311
|
+
it 'removes multiple entities' do
|
|
312
|
+
added_entities = index.bulk_add(entities)
|
|
313
|
+
|
|
314
|
+
assert_equal added_entities, index.all
|
|
315
|
+
|
|
316
|
+
index.bulk_delete(added_entities.map(&:uid))
|
|
317
|
+
|
|
318
|
+
assert_equal [], index.all
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
describe 'has_uid?' do
|
|
323
|
+
it 'fails with unknown uid' do
|
|
324
|
+
refute index.has_uid?('unknown')
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
it 'succeeds with known uid' do
|
|
328
|
+
added_entity = index.add(entity)
|
|
329
|
+
|
|
330
|
+
assert index.has_uid?(added_entity.uid)
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
private
|
|
336
|
+
|
|
337
|
+
class Entity < Rohbau::Entity
|
|
338
|
+
attributes :uid, :name
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
class OwnMapper
|
|
16
342
|
end
|
|
17
343
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rohbau
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jakob Holderbaum
|
|
@@ -12,7 +12,7 @@ authors:
|
|
|
12
12
|
autorequire:
|
|
13
13
|
bindir: bin
|
|
14
14
|
cert_chain: []
|
|
15
|
-
date: 2016-
|
|
15
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: thread_safe
|
|
@@ -141,6 +141,7 @@ files:
|
|
|
141
141
|
- lib/rohbau/default_memory_gateway.rb
|
|
142
142
|
- lib/rohbau/entity.rb
|
|
143
143
|
- lib/rohbau/event_tube.rb
|
|
144
|
+
- lib/rohbau/failure.rb
|
|
144
145
|
- lib/rohbau/index.rb
|
|
145
146
|
- lib/rohbau/interface.rb
|
|
146
147
|
- lib/rohbau/it_behaves_like.rb
|
|
@@ -153,7 +154,7 @@ files:
|
|
|
153
154
|
- lib/rohbau/runtime_loader.rb
|
|
154
155
|
- lib/rohbau/service_factory.rb
|
|
155
156
|
- lib/rohbau/shared_spec.rb
|
|
156
|
-
- lib/rohbau/
|
|
157
|
+
- lib/rohbau/success.rb
|
|
157
158
|
- lib/rohbau/use_case.rb
|
|
158
159
|
- lib/rohbau/version.rb
|
|
159
160
|
- rakelib/build_readme.rake
|
|
@@ -162,11 +163,14 @@ files:
|
|
|
162
163
|
- rakelib/rubocop.rake
|
|
163
164
|
- rohbau.gemspec
|
|
164
165
|
- spec/event_tube_spec.rb
|
|
166
|
+
- spec/failure_spec.rb
|
|
165
167
|
- spec/interface_spec.rb
|
|
166
168
|
- spec/runtime_loader_spec.rb
|
|
167
169
|
- spec/service_factory_spec.rb
|
|
168
170
|
- spec/shared_spec_spec.rb
|
|
169
171
|
- spec/spec_helper.rb
|
|
172
|
+
- spec/success_spec.rb
|
|
173
|
+
- spec/unit/rohbau/entity_spec.rb
|
|
170
174
|
- spec/unit/rohbau/index_spec.rb
|
|
171
175
|
homepage: http://www.neopoly.de/
|
|
172
176
|
licenses:
|
|
@@ -194,9 +198,12 @@ specification_version: 4
|
|
|
194
198
|
summary: Provides a set of patterns used in Domain Driven Design
|
|
195
199
|
test_files:
|
|
196
200
|
- spec/event_tube_spec.rb
|
|
201
|
+
- spec/failure_spec.rb
|
|
197
202
|
- spec/interface_spec.rb
|
|
198
203
|
- spec/runtime_loader_spec.rb
|
|
199
204
|
- spec/service_factory_spec.rb
|
|
200
205
|
- spec/shared_spec_spec.rb
|
|
201
206
|
- spec/spec_helper.rb
|
|
207
|
+
- spec/success_spec.rb
|
|
208
|
+
- spec/unit/rohbau/entity_spec.rb
|
|
202
209
|
- spec/unit/rohbau/index_spec.rb
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
module Rohbau
|
|
2
|
-
module SharedSpecs
|
|
3
|
-
DefaultGateway = Proc.new do
|
|
4
|
-
describe 'add' do
|
|
5
|
-
it 'inserts an entity' do
|
|
6
|
-
subject.add entity
|
|
7
|
-
assert_equal 1, subject.size
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it 'returns a copied entity' do
|
|
11
|
-
new_entity = subject.add entity
|
|
12
|
-
refute_equal new_entity.object_id, entity.object_id
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'assigns a string uid to the entity' do
|
|
16
|
-
new_entity = subject.add entity
|
|
17
|
-
refute_nil new_entity.uid
|
|
18
|
-
assert_kind_of String, new_entity.uid
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it 'raises an error if entity is nil' do
|
|
22
|
-
assert_raises ArgumentError do
|
|
23
|
-
subject.add nil
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'raises an error if entity has already an uid' do
|
|
28
|
-
entity.uid = '45'
|
|
29
|
-
assert_raises ArgumentError do
|
|
30
|
-
subject.add entity
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe 'bulk_add' do
|
|
36
|
-
it 'inserts a collection of entities' do
|
|
37
|
-
entities = [entity, updated_entity]
|
|
38
|
-
|
|
39
|
-
subject.bulk_add entities
|
|
40
|
-
assert_equal 2, subject.size
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'returns a collection copied entities' do
|
|
44
|
-
entities = [entity]
|
|
45
|
-
|
|
46
|
-
new_entities = subject.bulk_add entities
|
|
47
|
-
refute_equal new_entities[0].object_id, entities[0].object_id
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'assigns a string uid to the entities' do
|
|
51
|
-
entities = [entity]
|
|
52
|
-
|
|
53
|
-
new_entities = subject.bulk_add entities
|
|
54
|
-
refute_nil new_entities[0].uid
|
|
55
|
-
assert_kind_of String, new_entities[0].uid
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'raises an error if entities are nil' do
|
|
59
|
-
assert_raises ArgumentError do
|
|
60
|
-
subject.bulk_add [nil]
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'raises an error if entity has already an uid' do
|
|
65
|
-
entity.uid = '45'
|
|
66
|
-
assert_raises ArgumentError do
|
|
67
|
-
subject.bulk_add [entity]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe 'all' do
|
|
73
|
-
it 'returns an empty array' do
|
|
74
|
-
assert_equal [], subject.all
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it 'returns added entities' do
|
|
78
|
-
entities = [entity, updated_entity].map do |e|
|
|
79
|
-
subject.add e
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
assert_equal entities, subject.all
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe 'get' do
|
|
87
|
-
it 'returns nothing if uid not found' do
|
|
88
|
-
assert_equal nil, subject.get('23')
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it 'raises an error if uid is an invalid value' do
|
|
92
|
-
["", nil, 22].each do |value|
|
|
93
|
-
assert_raises ArgumentError do
|
|
94
|
-
subject.get(value)
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it 'returns the entity for a known uid' do
|
|
100
|
-
entities = [entity, updated_entity].map do |e|
|
|
101
|
-
subject.add e
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
assert_equal entities.first, subject.get(entities.first.uid)
|
|
105
|
-
assert_equal entities.last, subject.get(entities.last.uid)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
describe 'entity duplication' do
|
|
110
|
-
it 'returns a copy of the stored entity on get' do
|
|
111
|
-
uid = subject.add(entity).uid
|
|
112
|
-
|
|
113
|
-
e = subject.get(uid)
|
|
114
|
-
e.uid = uid + '1'
|
|
115
|
-
|
|
116
|
-
assert_equal uid, subject.get(uid).uid
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it 'returns a copy of the stored entity on add' do
|
|
120
|
-
result = subject.add(entity)
|
|
121
|
-
uid = result.uid
|
|
122
|
-
|
|
123
|
-
result.uid = uid + '1'
|
|
124
|
-
|
|
125
|
-
assert_equal uid, subject.get(uid).uid
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it 'adds a copy as stored entity on add' do
|
|
129
|
-
uid = subject.add(entity).uid
|
|
130
|
-
|
|
131
|
-
entity.uid = uid + '1'
|
|
132
|
-
|
|
133
|
-
assert_equal uid, subject.get(uid).uid
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it 'returns copies of the stored entities on all' do
|
|
137
|
-
uid = subject.add(entity).uid
|
|
138
|
-
|
|
139
|
-
e = subject.all.first
|
|
140
|
-
e.uid = uid + '1'
|
|
141
|
-
|
|
142
|
-
assert_equal uid, subject.get(uid).uid
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it 'returns a copy of the stored entity on update' do
|
|
146
|
-
stored = subject.add(entity)
|
|
147
|
-
uid = stored.uid
|
|
148
|
-
|
|
149
|
-
result = subject.update(stored)
|
|
150
|
-
|
|
151
|
-
result.uid = uid + '1'
|
|
152
|
-
|
|
153
|
-
assert_equal uid, subject.get(uid).uid
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it 'returns copies of the stored entities on bulk_add' do
|
|
157
|
-
entities = [entity]
|
|
158
|
-
|
|
159
|
-
results = subject.bulk_add(entities)
|
|
160
|
-
uid = results[0].uid
|
|
161
|
-
|
|
162
|
-
results[0].uid = uid + '1'
|
|
163
|
-
|
|
164
|
-
assert_equal uid, subject.get(uid).uid
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it 'adds copies as stored entities on bulk_add' do
|
|
168
|
-
entities = [entity]
|
|
169
|
-
|
|
170
|
-
results = subject.bulk_add(entities)
|
|
171
|
-
uid = results[0].uid
|
|
172
|
-
|
|
173
|
-
entity.uid = uid + '1'
|
|
174
|
-
|
|
175
|
-
assert_equal uid, subject.get(uid).uid
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
describe 'update' do
|
|
180
|
-
it 'fails if nil is given' do
|
|
181
|
-
assert_raises ArgumentError do
|
|
182
|
-
subject.update(nil)
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
it 'fails if uid is nil' do
|
|
187
|
-
assert_raises ArgumentError do
|
|
188
|
-
entity.uid = nil
|
|
189
|
-
subject.update(entity)
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it 'fails if uid is not known' do
|
|
194
|
-
assert_raises ArgumentError do
|
|
195
|
-
entity.uid = "22"
|
|
196
|
-
subject.update(entity)
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
it 'updates and returns the entity' do
|
|
201
|
-
added_entity = subject.add(entity)
|
|
202
|
-
uid = added_entity.uid
|
|
203
|
-
|
|
204
|
-
updated_entity.uid = uid
|
|
205
|
-
result = subject.update(updated_entity)
|
|
206
|
-
|
|
207
|
-
assert_equal subject.get(uid), result
|
|
208
|
-
refute_equal added_entity, result
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
describe 'delete' do
|
|
213
|
-
it 'fails if nil is given' do
|
|
214
|
-
assert_raises ArgumentError do
|
|
215
|
-
subject.delete(nil)
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
it 'fails if uid is not known' do
|
|
220
|
-
assert_raises ArgumentError do
|
|
221
|
-
subject.delete('22')
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it 'deletes the entity' do
|
|
226
|
-
uid = subject.add(entity).uid
|
|
227
|
-
|
|
228
|
-
assert subject.get(uid)
|
|
229
|
-
|
|
230
|
-
subject.delete(uid)
|
|
231
|
-
|
|
232
|
-
refute subject.get(uid)
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
it 'returns deleted entity' do
|
|
236
|
-
uid = subject.add(entity).uid
|
|
237
|
-
|
|
238
|
-
persisted_entity = subject.get(uid)
|
|
239
|
-
|
|
240
|
-
assert_equal persisted_entity, subject.delete(uid)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
it 'removes the entity from the collection' do
|
|
244
|
-
uid = subject.add(entity).uid
|
|
245
|
-
subject.add(updated_entity)
|
|
246
|
-
|
|
247
|
-
subject.delete(uid)
|
|
248
|
-
|
|
249
|
-
assert_equal 1, subject.all.size
|
|
250
|
-
refute_includes subject.all.map(&:uid), uid
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
describe 'bulk_delete' do
|
|
255
|
-
it 'raises an error if nil is given' do
|
|
256
|
-
assert_raises ArgumentError do
|
|
257
|
-
subject.bulk_delete([nil])
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
it 'raises an error if uid is not known' do
|
|
262
|
-
assert_raises ArgumentError do
|
|
263
|
-
subject.bulk_delete(['22'])
|
|
264
|
-
end
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
it 'deletes the entities' do
|
|
268
|
-
uid = subject.add(entity).uid
|
|
269
|
-
uids = [uid]
|
|
270
|
-
|
|
271
|
-
assert subject.get(uid)
|
|
272
|
-
|
|
273
|
-
subject.bulk_delete(uids)
|
|
274
|
-
|
|
275
|
-
refute subject.get(uid)
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
it 'returns deleted entity' do
|
|
279
|
-
uid = subject.add(entity).uid
|
|
280
|
-
uids = [uid]
|
|
281
|
-
|
|
282
|
-
persisted_entity = subject.get(uid)
|
|
283
|
-
|
|
284
|
-
assert_equal persisted_entity, subject.bulk_delete(uids)[0]
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
it 'removes the entity from the collection' do
|
|
288
|
-
uid = subject.add(entity).uid
|
|
289
|
-
uids = [uid]
|
|
290
|
-
|
|
291
|
-
subject.add(updated_entity).uid
|
|
292
|
-
|
|
293
|
-
subject.bulk_delete(uids)
|
|
294
|
-
|
|
295
|
-
assert_equal 1, subject.all.size
|
|
296
|
-
refute_includes subject.all.map(&:uid), uid
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
end
|
|
301
|
-
end
|